Continued "Non-professional code Nong Java Learning Note 5 Java Tools classes and Algorithms"
V. String of strings
String and character differences: string double quotation marks "n", character enclosed in single quotation marks, denotes a symbol ' \ n '
The main methods and properties of 1.string
Class |
Method or Property |
Note |
Define String |
Stirng s=new String ("value"), String s= "value" |
|
Property |
The length of the string.length:string is byte |
|
Method Startswith,endswith |
S.startwith ("value")-starts with a value, S.endswith ("")-end |
|
Method: Find IndexOf |
S.indexof ("value")-Find where the value first appears (0 start) |
|
|
S.lastindexof ("")-the location where the last occurrence of the value was found |
|
|
(char) s.charat (int index)-Find out the characters of the first few |
|
|
(last) IndexOf (Str,strindex), find this character is the same as the first str ... |
|
Method: Compare |
Bool s.equals (S0), S.compareto (S2), result 1,0,-1 (C #) |
|
Method: Connect Concat |
S.concat (S0), equivalent to + |
|
StringBuffer (C#stringbuilder) |
After instantiation: Append ("value") is added; Insert (n, "value"); Setchatat (n, ' value ')-N is index |
|
2.javaapplication command line parameters (input) Usercomlparameter.java
public class Usercomlparameter
{
public static void Main (String args[])//args[] array, you can lose an indefinite number of String
{
int a1,a2,a3;
if (args.length<2)
{
System.out.println ("Run this program should provide two command line parameters");
System.exit (0);
}
A1=integer.parseint (Args[0]);//define a good type for easy calculation
A2=integer.parseint (Args[1]);
A3=A1*A2;
The product of System.out.println (a1+ "and" +a2+ "equals" +a3 ");
}
}
Command line: Javac Usercomlparameter.java then Java usercomlparameter 52-4, where two parameters are entered for the specific values
Vi. recursion (call yourself, grow up)
Long factorical (int n)
{
If (N==1)
Return 1;//Recursive header
Else
Return n.factorical (n-1);//Recursive call itself
}
Can be used to sequence the law of this type, step-by, limit the scope of the recursive head, and then layered, and finally careful not infinite loop
Seven, sort (by understanding, with C # almost, here only write the principle)
1. Bubble-22 contrast, the order of large, reverse take small, and then with the back of the ratio; traverse the n-1 wheel
2. Select Sort-Select the smallest or largest from the target, and put in the sorting sequence; Repeat work is always selected.
3. Insert Sort: Select, here is a sequence based on the virtual position to draw a number of a sequence
4. System sort function: (void) sort ("");
Eight, find
1. Sequential Lookup: Traversal
2. On the sub-search-the middle number, divided into two columns, greater than alive less than, exclude a column ... Keep going.
3. System Lookup: Arrays's BinarySearch ([array],key key value)
Nine, the list of ten, queue Xi., stack 12, fork Tree
(slightly, have time to take a look carefully, perhaps will use, usually the project less use, someone see feel important say a sound, I look again)
Non-professional Code Nong Java Learning note 6java Tools class and algorithm-string