Learn Java Notes (2)

Source: Internet
Author: User
Tags array array definition arrays end variables sort variable tostring
Notes

31. Converted from encapsulated object to basic data type: obj. Xxxvalue (); obj is an object that encapsulates the class, and XXX is the representation of the encapsulated object

The base data type.
32, converted from string to basic data type: obj.parsexxx (string str); obj is the object that encapsulates the class, and XXX is the encapsulated object

The basic data type represented by the

.
33, converted from string to encapsulated object: obj.valueof (String str).
34, converted from encapsulated object to string: Obj.tostring ().
35, converted from base data type to String: Obj.tostring (XXX value).
36, not equal to:!=
37, operator instanceof, such as V1 instanceof v2. Checks whether the object V1 is an instance of Class V2.
38, the formulas on both sides of the logical operator need to belong to a Boolean. Unlike C + +, integers other than 0 are considered true in C + +.
39, bit (bitwise) logical operator: &, V1 & v2. Bit and, if the relative bit is 1, then 1, otherwise 0
        |, v1 | v2. Bit or, if the relative bit is 0, then 0, otherwise 1
        ^, v1 ^ V2. Bit XOR, if the relative bit has the same value, then 0, otherwise 1
                              ~, ~v1. V1 's complement, 1 becomes 0, 0 becomes 1.
    v1 and v2 must be of integer type.
40, Java does not support operation overloading, nor does it support C + +:: And >> and << operators.
41, constant specified: static final int NUM = 1.
42, array definition: int num []; or int [] num; num=new int]; or int [] num=new num[15]; or int

num[]={1,2,3,4,5};
43, if the two-dimensional array of the length of the 2nd dimension is different, because the array variable itself is a reference type, you can point the 1th dimension to another array.
44. Copy array: void Arraycopy (Object src,int srcposition,object dest,int destposition,int

Length) or clone () for example int [] newa= (int []) a.clone ();
45, the arrays class provides some array operations, such as sorting and searching
static void sort (datatype[] data): Arranges the elements within the array data from small to large (using quicksort)
static void sort (datatype[] data,int fromindex,int toindex)
static int BinarySearch (datatype[] data,datatype key): Searching array data using binary search

The element key (which must be ordered beforehand). Returns the position of key in data if it is searched, and the return value, if not found, is (-plug

In point-1, the insertion point is the first large and the index of the element value to search for.
static void Fill (datatype[] data,datatype val): Sets the elements within the array to Val.
static void Fill (datatype[] data,int fromindex,int toindex,datatype val)
46. In Java, char arrays and string classes do not end with '. The char array is not equal to the string object, the array is mutable,

However, the string object is invariant.
47. Converts a char array to a string object. Char[] data={' s ', ' t ', ' r ', ' I ', ' n ', ' G '}; String str=new

String (data);
48, Length () to get a string of lengths, and length can be used to get the number of elements contained in an array.
49, because the Java object is a reference type, therefore, string1==string2, just compare variables string1 and string2 to point to

The same address does not compare the contents of the string.
50, int compareTo (String str): S1.compareto (S2). If S1 and S2 are equal, return 0; If s1>s2, the return value is greater than

0; If s1<s2, the return value is less than 0.
int comparetoingnorecase (String str): s1.comparetoingorecase (S2). Ignores case.
Boolean equals (Object obj): s1.equals (S2).
Boolean equalsignorecase (String str): s1.equalsignorecase (S2).
51, search and read part of the string operation:
Boolean startswith (String str): Check to see if STR is at the front of the string
Boolean endsWith (String str)
int indexOf (char ch): Gets the position where CH first appears in the string and returns 1 if it cannot be found
int indexOf (String str)
int LastIndexOf (char ch): Search from the back, get the first occurrence of CH in the string, if the return cannot be found

Back to-1
int LastIndexOf (String str)
string substring (int begin): Generates a new string that contains all of the original string positions that begin to the end

Character
String substring (int begin,int end)
52, StringTokenizer (String str): Use the default delimiter to parse a string, which is: ', ' \ t ', ' \ n '

, ' \ R ', ' \f '.
StringTokenizer (String str,string delimiter): Parsing a string using the specified delimiter
53. The StringBuffer class is used to generate string buffers, which are called variable strings. Default capacity for StringBuffer objects

Quantity is 16 characters.
54. StringBuffer cannot directly assign a string to a StringBuffer object like a string object, such as StringBuffer

Mystring3= "This is Worong". You must use new to generate the StringBuffer object.
55, the StringBuffer object has the capacity and the length cent, the capacity is invariable, the length is variable. The length is less than or equal to the capacity, representing the actual

The number of characters stored.
56.int capacity (): Returns the capacity of the StringBuffer object.
int length (): Returns the length of the StringBuffer object.
StringBuffer Append (dataType data): Add data back to StringBuffer object
StringBuffer Insert (int offset,datatype data): Inserts data in front of the offset position
String toString (): Converts a StringBuffer object to a String object.
57, when the length of the stored string exceeds its capacity, the capacity will be changed to twice times the original capacity plus 2. Predetermined sufficient capacity for high efficiency
58, data members represent the variables declared within the class, divided into static (class variables) and non-static (instance variables)
59, the method within the class is divided into static (class method) and Non-static (instance method)
60, each object has a own instance variable and the variable value, through the object to access the instance variable.




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.