Java string Processing

Source: Internet
Author: User

Just learned, the comments are written very completely do not explain, there may be comments are not all welcome to the big God and I discuss the exchange. The landlord of a cabbage,,,,

 Packageclass.string;ImportJava.util.Scanner;/*** String Test *@authorAdministrator **/ Public classStringtest { Public Static voidMain (string[] args) {Scanner input=NewScanner (system.in); //define two default stringsString entry = "ABCDA"; String Entry1= "1,2,3,4,1"; System.out.println ("* * * * * * * * * * * * * * * * * * *"); System.out.println (The first string defaults to: "+entry+" \ n the second string defaults to: "+entry1); System.out.println ("* * * * * * * * * * * * * * * * * * *"); intSeat = Entry.indexof ("C");//find the location of C, no seat value is negative oneSystem.out.println ("\ n" +entry+ "starting from 0 Number" C "in the first" +seat+ "bit \ n"); System.out.println (Entry+ "Total" +entry.length () + "characters");//Length () to get string lengthsString x= Entry.tolowercase ();//convert tolowercase () to lowercaseString d = entry.touppercase ();//convert toUpperCase () to uppercaseSystem.out.println ("\ n lowercase:" +x+ "\ n Uppercase:" +d); String A1= "ABCDA";//input D vs. A1 Ignore case comparison                BooleanA = entry.equalsignorecase (A1);//true Equalsignorecase () ignores case if case is ignored equal to a                if(a) System.out.println ("\ nthe password is" +entry+ "ignores case"); String Add= Entry+entry1;//Method 1String add1 = entry1.concat (entry);//Method 2System.out.println ("\ n Two string connection: Method 1" +add+ "Method 2" +add1); intappear = Entry1.indexof ("1");//find the position of the first 1 in 12341        intAPPEAR1 = Entry1.lastindexof ("1");//find the last 1 position in 12341                intAPPEAR2 = Entry.indexof (97);//b where the ASCII code is 98        intAPPEAR3 = Entry.lastindexof (97);//b where the ASCII code is 98System.out.println (\ nthe position of the first 1 in "\ +entry1+" starting from 0: "+appear+" \ T in the last 1 position "+appear1); System.out.println ("\ n starting from 0 the position of the first A in" +entry+ ":" +appear2+ "\ T in the position of the last a" +appear3); String Extract= Entry.substring (2);//ABCDA to intercept from the second position .String Extract1 = entry.substring (1, 4);//ABCDA to intercept from the second position .System.out.println ("\ n" +entry+ "starting from 0 the second digit (inclusive) begins to intercept all of the following, interception obtained:" +extract); System.out.println ("\ n" +entry+ "specifies the range intercept, starting from 0 the first digit (inclusive) to the fourth bit (not included) between the contents:" +Extract1); String out= Entry1.trim ();//Remove SpacesSystem.out.println ("\ n Go to space operation" +entry1+ "remove space after output:" +Out ); String split[]= Out.split (",");//with "," as the split flag, the split contents are stored in the split arraySystem.out.println ("\ n with", "for split flag, after split"); intj = 0;  for(inti=0; i<split.length; i++) {System.out.println ("\ n" + (i+1) + "one:" +Split[i]); J++; } System.out.println ("\ nthe" \ +j+ "characters are stored with a string array"); //StringBuffer class TestStringBuffer SB=NewStringBuffer ("\ n Hello");//Create, the initial value is Hello                intnum=112; StringBuffer SB1= Sb.append ("I'm Fine");//First time AddSystem.out.println (SB1); StringBuffer SB2= Sb1.append ("yes");//second addition, single character can be String type or char typeSystem.out.println (SB2); StringBuffer SB3= Sb2.append (num);//third time AddSystem.out.println (SB3); String b= "Helloword.java";//Create a stringSystem.out.println ("\n* * * * * * * * * * * * * * * * * * * *"); System.out.println ("A default string:" +C); System.out.println ("* * * * * * * * * * * * * * * * *"); System.out.println ("\ n Replace before:" +b); b= B.replace ("ll", "EE");//replacement method, replace "ll" with "EE"SYSTEM.OUT.PRINTLN ("After replace:" +b); System.out.println ("\ n" +b+ "does the. Jav end:" +b.endswith (". Jav"));//Determine if you think the ". Jav" End, which is obviously the end of ". Java", so the result is falseSystem.out.println (b+ "whether to start with H:" +b.startswith ("H"));//Judging whether to start with "H", where "Helloword.java" starts with "H", so the result is trueStringBuffer G=NewStringBuffer ("ABCDE");//Create a new StringBuffer string value of "AAAAA"System.out.println ("\n* * * * * * * * * * * * * * * *"); System.out.println ("A default string:" +g); System.out.println ("* * * * * * * * * * * * *"); G.setcharat (1, ' B ');//Specify replacementSystem.out.println ("\ n starts from 0 to replace the 2nd character with B:" +g); G.deletecharat (1);//Specify DeleteSystem.out.println ("\ nthe 2nd character is removed from the 0 start number:" +g); }}

Java string Processing

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.