Some common methods of string in Java share _java

Source: Internet
Author: User

1. Some common methods of string in Java

Copy Code code as follows:

/**
*
*/
Package Com.you.model;

/**
* @author Administrator
* @date 2014-02-24
*/
public class Replace {

/**
* @param args
*/
public static void Main (string[] args)
{
/**
* Original String
*/
String str = "78454545855KSDJNF dnfdksf klkade tgth eiru OaK l!@@$#%$^*& (* () () ><?<>>>";

/**
* CONCAT ()
*/
str = str.concat (str);
System.out.println ("First concat ():" + str);
System.out.println ();

/**
* Intern ()
*/
str = Str.intern ();
System.out.println ("Second intern ():" + str);
System.out.println ();

/**
* Replace ("", "")
*/
str = str.replace ("8", "rich");
System.out.println ("Third replace (',"): "+ str");
System.out.println ();

/**
* ReplaceAll ("", "")
*/
str = Str.replaceall ("f", "Amitabha");
System.out.println ("Fourth time ReplaceAll (', '):" + str);
System.out.println ();

/**
* Replacefirst ("", "")
*/
str = Str.replacefirst ("7", "7,749 Days");
System.out.println ("Fifth time Replacefirst (', '):" + str);
System.out.println ();

/**
* SUBSTRING ()
*/
str = str.substring (20);
System.out.println ("Sixth time substring ():" + str);
System.out.println ();

/**
* SUBSTRING (,)
*/
str = str.substring (25, 35);
System.out.println ("Seventh time substring (0,10):" + str);
System.out.println ();

/**
* toLowerCase ()
*/
str = Str.tolowercase ();
System.out.println ("Eighth Time toLowerCase ():" + str);
System.out.println ();

/**
* toUpperCase ()
*/
str = Str.touppercase ();
System.out.println ("Nineth Time toUpperCase ():" + str);
System.out.println ();

/**
* Trim ()
*/
str = Str.trim ();
SYSTEM.OUT.PRINTLN (Tenth Time trim (): "+ str");
System.out.println ();

/**
* Length ()
*/
int len = Str.length ();
SYSTEM.OUT.PRINTLN (11th time Length (): "+ len");
}

}

2. Results

Copy Code code as follows:

First concat (): 78454545855KSDJNF dnfdksf klkade tgth eiru OaK l!@@$#%$^*& (* () () ><?<>>> 78454545855KSDJNF dnfdksf klkade tgth eiru OaK l!@@$#%$^*& (* () () ><?<>>>


Second intern (): 78454545855KSDJNF dnfdksf klkade tgth eiru OaK l!@@$#%$^*& (* () () ><?<>>> 78454545855KSDJNF dnfdksf klkade tgth eiru OaK l!@@$#%$^*& (* () () ><?<>>>


Third time replace (', '): 7 Fortune 454545 Fortune 55ksdjnf dnfdksf klkade tgth eiru OaK l!@@$#%$^*& (* () () ><?<>>> 7 Fortune 454545 Fortune 55ksdjnf dnfdksf klkade tgth eiru OaK l!@@$#%$^*& (* () () ><?<>>>


Fourth time ReplaceAll (', '): 7 Fortune 454545 Fortune 55ksdjn amitabha dn Amitabha dks amitabha klkade tgth Eiru OaK (* () () ><?< >>>7 Fortune 454545 Fortune 55ksdjn amitabha dn Amitabha dks amitabha klkade tgth Eiru OaK (* () () ><?<>>>


Fifth time Replacefirst (', '): 7,749 days Fortune 454545 Fortune 55ksdjn amitabha dn Amitabha dks amitabha klkade tgth Eiru OaK (* () () l!@@$#%$^*&;? <>>>7 Fortune 454545 Fortune 55ksdjn amitabha dn Amitabha dks amitabha klkade tgth Eiru OaK (* () () ><?<>> >


Sixth time substring (): DJN amitabha dn Amitabha dks amitabha klkade tgth eiru OaK l!@@$#%$^*& (* () () ><?<>>> 7 Fortune 454545 Fortune 55ksdjn amitabha dn Amitabha dks amitabha klkade tgth eiru OaK l!@@$#%$^*& (* () () ><?<>>>


Seventh time substring (0,10): ADE tgth E


Eighth Time toLowerCase (): Ade Tgth E


Nineth Time toUpperCase (): ADE tgth E


Tenth time Trim (): ADE tgth E


11th time Length (): 10

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.