Java's string learning record

Source: Internet
Author: User

Java's string learning record


public class Stringdemo {


public static void Main (string[] args) {

Static initialization of strings

String S1 = "Hello china!";

String s3 = "Hello china!";

System.out.println (S1);

Dynamic initialization of strings

String s2 = new String ("Hello China!,china,china");

String S4 = new String ("Hello china!");

String s5 = "Hello Japan";

String s6 = "Hey,"; Hey,hello china!

String s7 = "Beijing | shanghai | nanjing | wuhan | Chengdu";

System.out.println (S1==S3);//true

System.out.println (S2==S4);//false

System.out.println (S2.equals (S4));//true

System.out.println (S1.charat (6));//Get character ' C '

Returns 0:S1==S5, negative s1<s5 positive S1>S5

System.out.println (S1.compareto (S5));

System.out.println (S6.concat (S1));

System.out.println (S6+S1);

System.out.println (S1.contains ("China"));//true

System.out.println (S1.contains ("Japan"));//false

byte[] arr = s1.getbytes ();

System.out.println (S2.indexof ("China"));

System.out.println (S2.lastindexof ("China"));

string[] Citys = S7.split ("\\|");

for (int i=0;i<citys.length;i++)

{

System.out.println (Citys[i]);

}

StringTokenizer st = new StringTokenizer (s7, "|");

System.out.println ("-------------------");

while (St.hasmoreelements ())

{

System.out.println (St.nextelement ());

}

System.out.println (S1.substring (6,s1.length ()-1));

System.out.println (S1.touppercase ());

System.out.println (S3.tolowercase ());

}


}


Java string Learning record

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.