java ---- commonly used class

A, String class

  All string literals (eg "abc") Java programs are implemented as an instance of this class. Strings are constant; their values ​​can not be changed after creation. String buffer supports variable strings. Because String objects are immutable, so you can share.

  • String constructor
  1. String () String object initialization a newly created, it represents an empty character sequence.
    String s1 = new String ();
  2. String (char [] value) assigned a new String, so that the character sequence represents a character array containing the current parameters.
    String s2 = new String (new char [] { 's', 'h', 's', 'x', 't'});
  3. String (char [] value, int offset, int count) Allocates a new String, which contains characters from a character array parameters sub-array.
    String s3 = new String (new char [] { 's', 'h', 's', 'x', 't'}, 2,3);
  4. String (byte [] bytes) byte array default character set specified by the decoded platform used to construct a new String.
  5. getBytes () using the platform's default character set encoding is byte String this sequence, storing the result into a new byte array.
  6. String (byte [] bytes, String charsetName) byte array specified by using the specified charset decoding, construct a new String.
    String s5 = new String (new byte [] {- 27, -101, -96, -28, -72, -70}, "GBK");
  7. Byte subarray String (byte [] bytes, int offset, int length) specified by the default character set using the decoded platform construct a new String.
    String s6 = new String (new byte [] {- 27, -101, -96, -28, -72, -70}, 3,3);
  • String Methods

String str=“shsxtgoooood”;

  1. char charAt (int index) Returns the char value at the specified index.
    str.charAt (2);
  2. int indexOf (String str) Returns the index *** substring in this string at the first occurrence
    str.indexOf ( "s");
  3. int indexOf (String str, int fromIndex ) Returns the index of the substring in the first occurrence of the string, the start position of the specified index.
    str.indexOf ( "s", 1) ;
  4. byte [] the getBytes () using the platform's default character set encoding is byte String this sequence, storing the result into a new byte array.
  5. String replace (char oldChar, char newChar) to replace the old string new string.
  6. tring [] split (String regex) regular expression matching string based on a given resolution.
  7. String substring (int beginIndex) Returns a new string that is a substring of this string.
  8. String substring (int beginIndex, int endIndex) endIndex Returns a new string not included, it is a child of this string.
  9. char [] toCharArray () converts this string to a new character array.
  • StringBuilder: variable-length string, thread-safe, high efficiency
  • StringBuffer: variable-length string, thread-safe, low efficiency
  1. The StringBuilder () Constructs a generator with a character string, an initial capacity of 16 characters.
  2. StringBuilder (String str) Constructs a string builder, and initialize the contents of the specified string.
  3. StringBuilder (int capacity) configured with a character string which is not generating an initial capacity specified by the capacity parameter.
  4. StringBuilder append (boolean b) splicing parameters

Two, Math Class

  1. static double floor (double a) rounded down
  2. static double ceil (double a) rounding up
  3. static double max (double a, double b) returns the larger of the two double one.
  4. static int min (int a, int b) two return int a smaller value.
  5. static long round (double a) Returns the closest long parameters.

Third, the basic data type of package type

Basic data types Packaging data types
byte Byte
short Short
int Integer
long Long
float Float
double Double
char Character
boolean Boolean
  • Autoboxing: from basic data types -> package type
  • Automatic unboxing: the type of packaging - Basic Data> Type
  • The Integer class wraps a primitive type int value in the object
    1.int and Integer (whether or not new) Comparison: unpacking occurs automatically, if the values are the same on the same.
    2. If two Integer, and if there is new, is not the same.
    3. If you are not new, and then to see whether a buffer within a range of objects, in the same, not different.
  • Integer method
  1. static int parseInt (String s) the string argument as a signed decimal integer resolution.
  2. static int parseInt (String s, int radix) radix is ​​specified using hexadecimal resolve what parameters s.

Four, Date class Date

  • Date constructor
  1. Date () date object is created (local) based on the current time.
  2. Date (long time) Construction of time based on the date specified object type milliseconds long.
  • Date Methods
  1. boolean after (Date when) Tests if this date is after the specified date.
  2. boolean before (Date when) Tests if this date is before the specified date.
  3. Object clone () Returns a copy of this object.
  4. int compareTo (Date anotherDate) Compares two dates.
  5. Equality compare two dates boolean equals (Object obj).
  6. void setTime (long time) Sets this Date object to represent after January 1, 1970 00:00:00 GMT point in time that is time milliseconds.

Five, SimpleDateFormat class date format

Specified format conversion between the string and the date the object

  • y: Year
  • M: month
  • d: Date
  • H: 24 Xiaoshi
  • h: 12 Xiaoshi
  • m: min
  • s: sec
  • S: ms

1. Set the format converter: SimpleDateFormat objects
the SimpleDateFormat () The default format conversion. Using the default pattern and the default date format locale symbol structure SimpleDateFormat.
2.SimpleDateFormat (String pattern) specified conversion format
3.format (Date) target date to a string
4. parse (String) String Date Switch Object

Six, enum enum class

All members of the enumeration class, is a current example of the type of equivalent public static final modification.
All enumeration implicitly inherit java.lang.Enum

enum Week{
	Mon,   //public static final Week Mon=new Week();
	Thus,
	Sun;
	private String name;
	//私有的构造器
	private Week(){	
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public void info(){
		System.out.println("成员方法"+this.name);
	}
}

Seven, File File Class

Constructor:
  abstract pathname to create a new File instance File (String pathname) by the given pathname string into.
method:

  1. boolean canWrite ()
    to test whether the application can modify the file denoted by this abstract pathname.
  2. boolean delete ()
    to remove this abstract pathname of the file or directory indicated.
  3. boolean exists ()
    Tests if this abstract pathname of the file or directory representation exists.
  4. File getAbsoluteFile ()
    Returns the absolute pathname of this abstract pathname form.
  5. String getAbsolutePath ()
    Returns the absolute pathname of this abstract pathname string.
  6. String getParent ()
    Returns the abstract pathname of the parent directory pathname string; if this pathname does not name a parent directory, or null.
  7. File getParentFile ()
    Returns the abstract pathname of this abstract pathname of the parent directory; if this pathname does not name a parent directory, null is returned.
  8. boolean isDirectory ()
    Tests if this abstract pathname of the file is a directory.
  9. boolean isFile ()
    Tests if this abstract pathname of the file is a standard file.
  10. boolean mkdir ()
    creates this abstract pathname specified directory.
  11. boolean mkdirs ()
    to create this abstract pathname of the directory, including any necessary but nonexistent parent directories.

Guess you like

Origin blog.csdn.net/qq_41899248/article/details/91396049
Recommended