Black Horse Programmer _ Common API Summary

Source: Internet
Author: User
Tags uppercase character

-------<a href= "http://www.itheima.com" target= "blank" >android training </a> <a href= "/http/ Www.itheima.com "target=" blank ">java training </a>, look forward to communicating with you! ----------

One. Object class:

1. Superclass of all reference data types (arrays, classes in class libraries, our custom classes)
2. Once our class inherits object, it has a method inherited from object:

Class object{

public int hashcode () {

function: Returns an int value as the key value of the hash table;
Default implementation: An int value generated based on the address of the object. Different objects, will return different values;
Later, our subclasses will rewrite.
}

Public final Class GetClass () {
Function: Gets the class object of this category
Default implementation: Get Class object
The final method cannot be overridden by a quilt class
}

Public String toString () {
Function: Returns the string representation of this object;
Default implementation: Class name + @ + Hex address (we're useless)
Rewrite: The property value of all members inside will be returned to a single string;
}

public boolean equals (Object obj) {
Function: Compare with parameter object is equal;
Default implementation: Compares the "address" with the argument for equality, and returns True if it is equal. (We're useless)
Rewrite: Compares all of our object's property values to the corresponding property values of the parameter and returns False if "All equals" returns true;
}

protected void Finalize () {
Function: This method is called before the garbage collector reclaims this object, and then the object space is removed;
Default implementation: None (Empty method)
Can be overridden as needed
}

Protected Object Clone () {
Function: Copy a copy of this object
Default implementation: Local method implementation
Rewrite as needed; Note: Classes that need to be assigned must implement the Cloneable interface
}

Two. String class:

1. Represents a String object;
2. The "value" of a string object cannot be changed, but the reference can be changed;
3. Features: Can be directly assigned a "literal";
4. Typical interview questions:

String S1 = "abc";
String s2 = "abc"
String s3 = new String ("abc");
System.out.println (S1 = = s2);//true
System.out.println (S1 = = S3);//false
-----------------------------------------------------------
String S1 = "Hello";
String s2 = "World";
String s3 = "HelloWorld";
String S4 = "Hello" + "world";
String S5 = s1 + "World";
String s6 = "Hello" + s2;
String s7 = s1 + s2;
System.out.println (s3 = = S4);//true
System.out.println (s3 = = S5);//false
System.out.println (s3 = = S6);//false
System.out.println (s3 = = s7);//false

5. Construction Method:

public string (): instantiates an empty string; effect equivalent to: string s = "";
public string (byte[] bytes): Constructs a string using a byte[] array. (Converts a byte[] array to a string)
Public String (byte[] bytes,int offset,int length): Converts part of a byte[] array to a String
Public String (char[] value): Converts a char[] array to a String;
Public String (char[] value,int offset,int count): Converts part of a char[] array to a String
public string (string original): Constructs a new string using a string

6. Common methods:

1). Judging function:

Boolean equals (Object obj): Overrides object. Case-sensitive comparisons
Boolean equalsignorecase (String str): case-insensitive comparison
Boolean contains (String str): Determines whether STR is included in this string;
Boolean startsWith (String str): Whether to start with Str
Boolean endsWith (String str): Whether to end with Str
Boolean isEmpty (): Whether it is an empty string;

2). Get Features:

int length (): Distinguishes the length property of an array. Gets the lengths of the internal character sequences;
char charAt (int index): Returns the character of the index position;
int indexOf (int ch): Returns the index value of the character ch in the string, if not included, returns-1;
int indexOf (String str): Returns the index of the string str that appears in the string. If not included, returns-1;
int indexOf (int ch,int fromIndex): Find a character ch, starting from FromIndex;
int indexOf (String Str,int fromIndex): Finds a string str, starting from FromIndex;
int lastIndexOf (int ch): From the back forward, from right to left, but the returned index is from left to right, starting from 0;

string substring (int start): A string that intercepts the start of a punch starting to the end. Generates a new string with the original string unchanged;
String substring (int start,int end): From start, intercept to end-1 (not including end)

3). Conversion function:

Byte[] GetBytes (): Converts a string to a byte[] array;
Char[] ToCharArray (): Converts this string to char[] array;
Static String valueOf (char[] CHS): Static method. Converts a char[] array to a string
static String valueOf (int i): static method. Converts an int value to a string;
String toLowerCase (): Converts a character in a string to lowercase;
String toUpperCase (): converted to uppercase;
String concat (String str): Connects the argument string to the end of the current string. The effect is the same as the "+" operator;

4). Other functions:

1. Replacement function

String replace (char Old,char new): Replaces the characters in a string with the new character, replacing the original old character. Generates a new string, unchanged;

String Replace (String old,string New): Replaces the original old string with the new string;

2. Remove the string two spaces
String trim (): Does not contain spaces in;

3. Compare two strings in a dictionary order
int CompareTo (String str)
int comparetoignorecase (String str)


Three. Scanner class:
1.boolean hasnextxxx ():
2.nextXxx ();

Four. StringBuffer class:
Buffer pool class for 1.String.
The difference between 2.String and StringBuffer:
1). String: Its "value" is immutable;
2). StringBuffer: Its "value" is variable;
When we do the concatenation of strings many times, the use of string creates a lot of garbage space. It is recommended to use this class;
2. Construction Method:
Public StringBuffer (): Initial capacity 16
public stringbuffer (int capacity): initial capacity capacity
Public StringBuffer (String str): Constructs a stringbuffer using string.
3. Add Features:
Public StringBuffer append (String str): and various overloaded methods. Add any type of parameter to the end;
Public stringbuffer Insert (int offset,string str): Inserts a String into the offset position. The characters in the original position are shifted back in turn;
4. Delete function:
Public stringbuffer deletecharat (int index): Delete character at index position
Public StringBuffer Delete (int start,int end): Deletes all characters from start to end-1;
5. Replacement function:
Public stringbuffer replace (int start,int end,string str): Replaces all characters at start to end with Str;
6. Invert function:
Public StringBuffer reverse (): reverses internal strings;
7. Interception function:
public string substring (int start): Intercepts the return of a new string from start to end;
Public String substring (int start,int end): Intercepts all characters from start to end-1;

Differences between the StringBuffer class and the StringBuilder class:
1.StringBuffer is thread-safe and inefficient;
2.StringBuilder is thread unsafe; high efficiency;

Five. Arrays class:
1. The class of the array operation, there is no construction method, the internal contains a large number of static tool methods;
2. Common methods:
1). public static String toString (int[] a): Converts the int[] array to a String representation;
2). public static void sort (int[] a): Ascending sort int[] array;
3). public static int BinarySearch (int[] a,int key): Binary finds the key value in the int[] array;

Six. Wrapper class:
   basic data type   wrapper type
  byte   byte
  short     Short
  int      Integer
  long   Lon G
  char   Character
  float   float
  double&nbs p;  Double
  boolean    boolean

Seven, Integer class:
  1. The interior can contain an int value. It also contains some other methods for manipulating int values;
  2. Constructor:
   1). Integer (int value): Converts an int value to an integer;
   2). Integer (string s): Converts a String to an integer;
  3.int and String conversions:
   1). string--int:
    a.integer-->int parseint (string s)---int
     b.integer-->integer valueOf (String s)--intvalue ()--int
   2). INT----string:
    a.string-valueOf (int n)-and string
    b.integer -->string toString (int t)--String

4. Common methods:
   public int intvalue (): Returns an int value inside an integer
   public static int parseint (string s): Converts a string to int   
   public static string toString (int i) : Converts int to string
   public static Integer valueOf (int i): Converts int to Integer
    public static integer valueOf (string s): Converts a string to an integer
    basic binary conversion:
   public static string tobinarystring (int i):int--> binary-->string
   public static string tooctalstring (int i): int-to octal-to string
   public static string tohexstring (int i): INT-----hex--and S Tring
    Decimal to other binary:
   public static String toString (int i,int radix): The I value of a certain binary, Converted to a string representation. Radix: binary
    Other decimal:
   public static int parseint (String s,int Radix) : Converts a binary string representation of S to a decimal int value. Radix is the binary number;

Automatic packing and disassembly of 5.jdk5:
1. Auto-Boxing: Converts the "basic data type" to the corresponding "wrapper type";
Integer intobj = 10;
2. Automatic unpacking: The "package type" is converted to the corresponding "basic data type";
int n = intobj;

6. Common Interview Questions:

Integer V1 = 127;

Integer v2 = 127;

System.out.println (v1 = = v2);//true

Integer v3 = 128;

Integer v4 = 128;

System.out.println (v3 = = v4);//false

Integer v5 = 127;

Integer v6 = new Integer (127);

System.out.println (v5 = = V6);//false;

Eight. Character class:
1.char Packaging class;
2. Construction Method:
Character (Char v):
3. Common methods:
public static Boolean isuppercase (char ch): Determines whether it is a uppercase character
public static Boolean islowercase (char ch): Determines whether it is lowercase characters;
public static Boolean isdigit (char ch): Determines whether a number
public static char touppercase (char ch): Converts the character ch to uppercase;
public static char toLowerCase (char ch): Converts the character ch to lowercase;

-------<a href= "http://www.itheima.com" target= "blank" >android training </a> <a href= "/http/ Www.itheima.com "target=" blank ">java training </a>, look forward to communicating with you! ----------

Black Horse Programmer _ Common API Summary

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.