Java中字符串的一些常見方法分享
1、Java中字符串的一些常見方法
/**
*
*/
package com.you.model;
/**
* @author Administrator
* @date 2014-02-24
*/
public class Replace {
/**
* @param args
*/
public static void main(String[] args)
{
/**
* 原字符串
*/
String str = "78454545855ksdjnf dnfdksf klkADE TGTH eiru oaK L!@@$#%$^*&(*()()><?<>>>";
/**
* concat()
*/
str = str.concat(str);
System.out.println("第一次concat():" + str);
System.out.println();
/**
* intern()
*/
str = str.intern();
System.out.println("第二次intern():" + str);
System.out.println();
/**
* replace("","")
*/
System.out.println("第三次replace('',''):" + str);
System.out.println();
/**
* replaceAll("","")
*/
System.out.println("第四次replaceAll('',''):" + str);
System.out.println();
/**
* replaceFirst("","")
*/
str = str.replaceFirst("7", "七七四十九天");
System.out.println("第五次replaceFirst('',''):" + str);
System.out.println();
/**
* substring()
*/
str = str.substring(20);
System.out.println("第六次substring():" + str);
System.out.println();
/**
* substring(, )
*/
str = str.substring(25, 35);
System.out.println("第七次substring(0,10):" + str);
System.out.println();
/**
* toLowerCase()
*/
str = str.toLowerCase();
System.out.println("第八次toLowerCase():" + str);
System.out.println();
/**
* toUpperCase()
*/
str = str.toUpperCase();
System.out.println("第九次toUpperCase():" + str);
System.out.println();
/**
* trim()
*/
str = str.trim();
System.out.println("第十次trim():" + str);
System.out.println();
/**
* length()
*/
int len = str.length();
System.out.println("第十一次length():" + len);
}
}
第七次substring(0,10):ADE TGTH e
第八次toLowerCase():ade tgth e
第九次toUpperCase():ADE TGTH E
第十次trim():ADE TGTH E
第十一次length():10
[/code]
相關(guān)文章
Java如何處理數(shù)據(jù)成為樹狀結(jié)構(gòu)
這篇文章主要介紹了Java如何處理數(shù)據(jù)成為樹狀結(jié)構(gòu)問題,具有很好的參考價(jià)值,希望對大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-07-07
解決IDEA鼠標(biāo)點(diǎn)擊光標(biāo)變大問題
這篇文章主要介紹了解決IDEA鼠標(biāo)點(diǎn)擊光標(biāo)變大問題,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2021-02-02
org.apache.ibatis.binding.BindingException異常報(bào)錯(cuò)原因以及詳細(xì)解決方案
這篇文章主要給大家介紹了關(guān)于org.apache.ibatis.binding.BindingException異常報(bào)錯(cuò)原因以及詳細(xì)解決方案的相關(guān)資料,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2023-02-02
Java中的CountDownLatch、CyclicBarrier和semaphore實(shí)現(xiàn)原理解讀
這篇文章主要介紹了Java中的CountDownLatch、CyclicBarrier和semaphore實(shí)現(xiàn)原理詳解,CountDownLatch中調(diào)用await方法線程需要等待所有調(diào)用countDown方法的線程執(zhí)行,這就很適合一個(gè)業(yè)務(wù)需要一些準(zhǔn)備條件,等準(zhǔn)備條件準(zhǔn)備好之后再繼續(xù)執(zhí)行,需要的朋友可以參考下2023-12-12

