Chapter 6, String (one)---initialization, string manipulation (29th,feb)

Source: Internet
Author: User

 Public Static voidMain (string[] args) {//StringString str = "string constant string constant"; String str1=NewString ("string constant");//Construction MethodString str2 =NewString ("string constant");//new open space for memoryString STR3 = "string Constant"; System.out.println ("Str=" +str); System.out.println ("Str1=" +str1); System.out.println ("Str2=" +str2); Char[]c=New Char[]{' Me ', ' very ', ' good '}; String STR4=NewString (c); System.out.println ("str4=" +STR4);

// The "= =" operation, which compares memory addresses for equality        System.out.println ("STR1=STR2:" + (str1==str2));        System.out.println ("STR1=STR:" + (str1==str));        System.out.println ("STR=STR2:" + (str==str2));        System.out.println ("STR=STR3:" + (str==str3));                System.out.println ("STR1=STR2:" +str1.equals (str2));        System.out.println ("STR1=STR:" +str1.equals (str));

// String Information         // string length        System.out.println ("String length =" +str.length ());         // returns the index value        of the first word after finding the position of the substring in the string, after going to the SYSTEM.OUT.PRINTLN ("Constant word Position:" +str.indexof ("constant"));        System.out.println ("constant Position:" +str.indexof ("constant"));         // not found, return value -1        System.out.println ("My Position:" +str.indexof ("I"));         // returns the    index value        of the first word found from the position of the substring in the forward-looking string. System.out.println ("The position of the last constant word:" +str.lastindexof ("constant"));

// Get character        Char C1=str.charat (4);        System.out.println ("c1=" +c1);

Chapter 6, String (one)---initialization, string manipulation (29th,feb)

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.