Non-professional Code Nong Java Learning note 6java Tools class and algorithm-string

Source: Internet
Author: User

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

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.