Java string processing

Source: Internet
Author: User

Java string processing
I just learned that the comments are not fully explained. You may also be welcomed to discuss them with me. A Chinese cabbage, and package Class. string; import java. util. tests;/*** String test * @ author Administrator **/public class StringTest {public static void main (String [] args) {internal input = new partition (System. in); // define two default strings: String entry = "aBcDa"; String entry1 = "1, 2, 4, 1"; System. out. println ("********************"); System. out. println ("the first string defaults to:" + entry + "\ n the second string defaults to:" + entry1); System. out. println ("********************"); int seat = entry. indexOf ("c"); // locate the position of c. If no seat value is set, the value is negative. out. println ("\ n" + entry + "starting from 0" c "in" + seat + "bit \ n"); System. out. println (entry + "Total" + entry. length () + "characters"); // length () returns the String length String x = entry. toLowerCase (); // toLowerCase () to lowercase String d = entry. toUpperCase (); // toUpperCase () is converted to uppercase System. out. println ("\ n lower case:" + x + "\ n upper case:" + d); String a1 = "abcda "; // The input d and a1 are case-insensitive. boolean a = entry. when signorecase (a1); // if case-insensitive a is ignored, true then signorecase () ignores case-insensitive if (a) System. out. println ("\ n password is" + entry + "case-insensitive"); String add = entry + entry1; // method 1 String add1 = entry1.concat (entry ); // method 2 System. out. println ("\ n two string connections: method 1" + add + "method 2" + add1); int appear = entry1.indexOf ("1 "); // locate int appear1 = entry1.lastIndexOf ("1") at the first 1 in 12341; // locate int appear2 = entry in the last 1 in 12341. indexOf (97); // The location of B. The ASCII code of B is 98 int appear3 = entry. lastIndexOf (97); // location of B. The ASCII code of B is 98 System. out. println ("\ n starts from 0" + entry1 + "position of the first 1:" + appear + "\ t position of the last 1" + appear1 ); system. out. println ("\ n starts from 0" + entry + "the first location of a:" + appear2 + "\ t the last location of a" + appear3 ); string extract = entry. substring (2); // abcda truncates String extract1 = entry from the second position. substring (1, 4); // abcda intercepts System from the second place. out. println ("\ n" + entry + "starts from 0. The second digit (included) is used to extract all the subsequent content and obtain:" + extract); System. out. println ("\ n" + entry + "specifies the range to intercept, from 0 to the first (inclusive) to the fourth (excluded):" + extract1 ); string out = entry1.trim (); // remove the space System. out. println ("\ n Space removal operation" + entry1 + "output after space removal:" + out); String split [] = out. split (","); // use "," as the shard flag to save the shard content to the split array System. out. println ("\ n uses", "as the shard flag, after splitting"); int j = 0; for (int I = 0; I <split. length; I ++) {System. out. println ("\ n" + (I + 1) + ":" + split [I]); j ++;} System. out. println ("\ n split into" + j + "characters stored in string array"); // StringBuffer test StringBuffer sb = new StringBuffer ("\ n hello "); // create, the initial value is Hello int num = 112; StringBuffer sb1 = sb. append ("I'm fine"); // Add System for the first time. out. println (sb1); StringBuffer sb2 = sb1.append ("ah"); // added for the second time. A single character can be String or char System. out. println (sb2); StringBuffer sb3 = sb2.append (num); // Add System for the third time. out. println (sb3); String B = "helloword. java "; // create the string System. out. println ("\ n ******************"); System. out. println ("a default string:" + B); System. out. println ("*******************"); System. out. println ("\ n before replacement:" + B); B = B. replace ("ll", "EE"); // replace "ll" with "EE" System. out. println ("after replacement:" + B); System. out. println ("\ n" + B + "whether to use. end of jav: "+ B. endsWith (". jav "); // determines if it is ". the end of jav is obviously ". java "ends with false System. out. println (B + "whether to start with h:" + B. startsWith ("h"); // determines whether it starts with "h". Here, "helloword. java "starts with" h "and returns true StringBuffer g = new StringBuffer (" abcde "); // creates a StringBuffer string whose value is" aaaaa "System. out. println ("\ n **************"); System. out. println ("a default string:" + g); System. out. println ("***************"); g. setCharAt (1, 'B'); // specify to replace System. out. println ("\ n starts from 0 and replaces 2nd characters with B:" + g); g. deleteCharAt (1); // specify to delete the System. out. println ("\ n deletes 2nd characters from 0:" + g );}

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.