Java Foundation--java Common classes

Source: Internet
Author: User
Tags abs natural logarithm pow square root string format

String is a final class that represents the immutable sequence of characters

public int Length ()
public char charAt (int index)
public boolean equals (Object anobject)
public int CompareTo (String anotherstring)
public int indexOf (String s)
public int indexOf (String s, int startpoint)
public int lastIndexOf (String s)
public int lastIndexOf (String s, int startpoint)
public boolean startsWith (String prefix)
public boolean endsWith (String suffix)
public boolean regionmatches (int firststart,string other,int otherstart, int length)


is the creation of a new string, the original string does not change
Public String substring (int startpoint)
Public String substring (int start,int end)
Pubic String replace (char Oldchar,char Newchar)
public string ReplaceAll (string old,string New)
public string trim ()//Remove the space that appears at the end of the current string, and the space in the middle does not go away
public string concat (String str)
Public string[] Split (string regex) splits this string based on the match of the given regular expression.




1. Conversion between string and basic data type, wrapper class
String-"basic data type, wrapper class: Call the corresponding wrapper classparsexxx (String str);
Basic data type, wrapper class--"string: calling the string overloadvalueOf ()Method ori + "";

2. Conversion of strings to byte arrays
String-"byte array: A string that invokes thegetBytes ()Method byte[]
byte array-"string: the constructor that invokes the string directlyNew String (b);

3. Conversion of strings to character arrays
string-character array: Call stringToCharArray ()Method char[]
Character array-"string: the constructor that invokes the string directlynew String (c);

conversion of 4.String to StringBuffer
string--"StringBuffer: Using the StringBuffer constructor:new StringBuffer (String str)
stringbuffer--"String: Using the StringBuffertoString ()Method

StringBuffer:Java.lang.StringBuffer: Representativevariable sequence of characters, you can make and delete the string
StringBuilder: java.lang.StringBuilder: Variable sequence of characters, jdk5.0 new additionthread insecure, more efficient than StringBuffer

Note: Efficiency on add: from High to low stringbuilder>stringbuffer>string

StringBuffer Append (String s), stringbuffer append (int n),
StringBuffer append (Object o), stringbuffer append (char n),
StringBuffer Append (long N), StringBuffer append (boolean n),
StringBuffer Insert (int index, String str)
Public StringBuffer Reverse ()
StringBuffer Delete (int startIndex, int endIndex)
public char charAt (int n)
public void Setcharat (int n, char ch)
StringBuffer replace (int startIndex, int endIndex, String str)
public int indexOf (String str)
Public String substring (int start,int end)
public int Length ()



Summary: Add: Append ()
Delete: delete (int startIndex, int endIndex)
Modify: Setcharat (int n, char ch)
Check: Ch Arat (int n)
Insert: Insert (int index, String str)
Invert: reverse ()///itself changed
Length: Length ()

Time-related classes: /strong>
1. Currenttimemills () under the System class; Commonly used to calculate the time difference
2.Date class: Java.util.Date and its subclasses java.sql.Date
getTime (): return from January 1970 1 The number of milliseconds that this date object represents since the day 00:00:00 GMT.
toString (): converts this Date object to the following form of String:dow mon dd hh:mm:ss zzz yyyy where: Dow is a day of the week (Sun, Mon, Tu E, Wed, Thu, Fri, Sat), ZZZ is the time standard
3.SimpleDateFormat class: java.text.SimpleDateFormat Easy Internationalization
Format 1: Date --Text using SimpleDateFormat's format () method
Formatted 2: public SimpleDateFormat (String pattern) the construction method can create an object in the format specified by the parameter pattern , which is called:
Public String format (date date) : party Format Time Object Date

Parse: PublicDate Parse (string source): parses the text from the beginning of the given string to generate a date.

  4.Calendar class Java.util.Calendar (Calendar) class

How to get a calendar instance
Using the Calendar.getinstance () method
The constructor that invokes its subclass GregorianCalendar.

An instance of the calendar is an abstract representation of the system time, with the Get (int field) method to obtain the desired time information. such as year, MONTH, Day_of_week, Hour_of_day, MINUTE, SECOND
public void Set (int field,int value)
public void Add (int field,int amount)
Public final Date GetTime ()
Public final void SetTime (date date)


Math class Java.lang.Math
ABS Absolute
Acos,asin,atan,cos,sin,tan Trigonometric Functions
sqrt square root
Pow (double a,doble b) a power of B
Log Natural logarithm
Exp e is the base index
Max (double a,double b)
Min (double a,double b)
Random () returns the number 0.0 to 1.0
Long round (double a) double type data A is converted to long (rounded)
Todegrees (double angrad) radians-angle
Toradians (double angdeg) angle, radians

The numeric range of the BigInteger class BigInteger class is much larger than the numeric range of the integer class, and can support integers of arbitrary precision.
Constructors
BigInteger (String val)
Common methods
Public BigInteger ABS ()
Public BigInteger Add (BigInteger val)
Public BigInteger Subtract (BigInteger val)
Public BigInteger Multiply (BigInteger val)
Public BigInteger Divide (BigInteger val)
Public BigInteger remainder (BigInteger val)
Public BigInteger pow (int exponent)
Public biginteger[] Divideandremainder (BigInteger val)


BigDecimal class Java.math.BigDecimal class. The BigDecimal class supports fixed-point numbers of any precision.
Constructors
Public BigDecimal (double val)
Public BigDecimal (String val)
Common methods
Public BigDecimal Add (BigDecimal augend)
Public BigDecimal Subtract (BigDecimal subtrahend)
Public BigDecimal Multiply (BigDecimal multiplicand)
Public BigDecimal Divide (BigDecimal divisor, int scale, int roundingmode)

Java Foundation--java Common classes

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.