Hand-Punched notes

Source: Internet
Author: User

String

String str = "ABC"; (String constants)

str = "Def"; (point to new String)

String str1 =new string ("Tom");

String str2 =str1;

STR1 = "Rose"; (Assigning a new string address to str1)

Output results

Char[] c= {' A ', ' B ', ' C '}

String Str3 =new string (c) (converts other types to strings)

Output

The length of the output STR3 str3.length band () is the method

STR1 = "ABC";

STR2 = "ABC";

Output = = true (= = Compare memory address)

STR1 =new String ("abc")

STR2 =new String ("abc")

Output = = False

Output (Str1.equals (STR2)); (Compare content equality)

Determine the beginning and end of a string

Output (Str1.startswith ("AB"));

Output (Str1.endwith ("C"))

Find the index value of a string

str1 = "Lkjhgfdsaqqqqqwertyuiop";

Output (Str1.indexof ("a")); (Find the index of a, no matter how many A is the first one from left to right)

Output (Str1.lastindexof ("a")); (in contrast to the above, find the first one from right to left)

Get substring

Str1.substring (Start end)

Output (str 1.charAt (1));

Replace

Str1.replace ("FD", "FD") (returns the replaced string)

Output ()

Go to Space

STR1 = "# tom #";

Output (Str1.replace ("", "")) (go to all spaces)

Output (Str1.trim ()); (Remove the front and back spaces only)

Str.replacceall ("", ""); (supports regular expressions)

Split using a specific delimiter, bar string Segmentation array
str1 = "abc#) def#) 123#) GGG";

String[] St=str.split ("#)");

Output (st.length);

Output (st[0]);

Variable character sequence

StringBuilder strb =new StringBuilder ("abc")

Strb.append ("Def")

Strb.append ("VB")

Strb.append ("AA")

Strb.append ("Def"). Append ("VB"). Append ("AA") (Another way)

StringBuffer stru =new stringbuffer ("Sdsds")

Stru.append ("SDFD")

String STR4 =stru.tostring ();

Output ()

Hand-Punched notes

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.