1. Some common methods of strings in Java
Copy the 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 time concat(): " + str);
System.out.println();
/**
* intern()
*/
str = str.intern();
System.out.println("Second intern():" + str);
System.out.println();
/**
* replace("","")
*/
str = str.replace("8", "Get rich");
System.out.println("The third replace('',''):" + str);
System.out.println();
/**
* replaceAll("","")
*/
str = str.replaceAll("f", "Amitabha");
System.out.println("The fourth time replaceAll('',''):" + str);
System.out.println();
/**
* replaceFirst("","")
*/
str = str.replaceFirst("7", "seven seven forty-nine days");
System.out.println("The fifth time replaceFirst('',''): " + str);
System.out.println();
/**
*substring()
*/
str = str.substring(20);
System.out.println("The sixth substring(): " + str);
System.out.println();
/**
* substring(, )
*/
str = str.substring(25, 35);
System.out.println("The seventh substring(0,10): " + str);
System.out.println();
/**
* toLowerCase()
*/
str = str.toLowerCase();
System.out.println("The eighth time toLowerCase(): " + str);
System.out.println();
/**
* toUpperCase()
*/
str = str.toUpperCase();
System.out.println("The ninth time toUpperCase(): " + str);
System.out.println();
/**
* trim()
*/
str = str.trim();
System.out.println("The tenth trim(): " + str);
System.out.println();
/**
*length()
*/
int len = str.length();
System.out.println("The eleventh length(): " + len);
}
}
2. Result
Copy the 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!@@$#%$^*&(*()()><?<>>>
The third time replace('',''): 7发财454545发财55ksdjnf dnfdksf klkADE TGTH eiru oaK L!@@$#%$^*&(*()()><?<>>>7 发财454545发财55ksdjnf dnfdksf klkADE TGTH eiru oaK L!@@$#%$^*&(*()()><?<>>>
The fourth time replaceAll('',''): 7 fortune 454545 fortune 55ksdjnAmitabhadnAmitabhadksAmitabhaklkADE TGTH eiru oaK L!@@$#%$^*&(*()()><?<>>> 7 Get rich 454545 Get rich 55ksdjn Amitabha dn Amitabha dks Amitabha klkADE TGTH eiru oaK L!@@$#%$^*&(*()()><?<>>>
The fifth time replaceFirst('',''): seventy-seven forty-nine days to get rich 454545 get rich 55ksdjn Amitabha dn Amitabha dks Amitabha klkADE TGTH eiru oaK L!@@$#%$^*&(*()()><?<>>>7 Get rich 454545 Get rich 55ksdjn Amitabha dn Amitabha dks Amitabha klkADE TGTH eiru oaK L!@@$#%$^*&( *()()><?<>>>
The sixth 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!@@$#%$^*&(*()()><?<>>>
The seventh substring(0,10): ADE TGTH e
The eighth time toLowerCase(): ade tgth e
The ninth toUpperCase(): ADE TGTH E
The tenth trim(): ADE TGTH E
Eleventh time length(): 10