当前位置: 首页 > news >正文

炫富做图网站web个人网站设计代码

炫富做图网站,web个人网站设计代码,山西忻州市疫情,怎么自己制作网址String方法 字符串拆分 可以将一个完整的字符串按照指定的分隔符划分为若干个子字符串 相关方法如下: 方法功能String[ ] split(String regex)//以regex分割将字符串根据regex全部拆分String[ ] split(String regex, int limit)将字符串以指定的格式,拆…

String方法

字符串拆分

可以将一个完整的字符串按照指定的分隔符划分为若干个子字符串

相关方法如下:

方法功能
String[ ] split(String regex)//以regex分割将字符串根据regex全部拆分
String[ ] split(String regex, int limit)将字符串以指定的格式,拆分为limit组

代码示例:实现字符串的拆分处理

 public static void main(String[] args) {String str = "hello world hello world";//全部拆分String[] result1 = str.split(" ");for(String s : result1) {System.out.print(s);}System.out.println();//部分拆分String[] result2 = str.split(" ", 2);for(String s : result2) {System.out.print(s);}}

拆分是特别常用的操作,一定要重点掌握。另外有些特殊字符作为分割符可能无法正确切分,需要加上转义。

举个例子:比如拆分IP地址

public static void main(String[] args) {String str = "192.168.1.1";String[] result = str.split("\\.");for(String s : result) {System.out.println(s);}}

运行结果如下:

注意事项:

1.字符"|","*","+"都得加上转义字符,前面加上"\\"

2.而如果是"\\",那么就得写成"\\\\"

3.如果一个字符串中有多个分割符,可以用"|"作为连字符

举个例子吧:多次拆分

public static void main(String[] args) {String str = "name=zhangsan&age=18";//第一种多次拆分的方法String[] result1 = str.split("&|=");for(String s : result1) {System.out.println(s);}System.out.println("=================");//第二种多次拆分的方法String[] result2 = str.split("&");for(String s : result2) {String[] temp = s.split("=");System.out.println(temp[0] + "\n" + temp[1]);}}

运行结果如下:

字符串的截取

从一个完整的字符串中截取出部分内容。可用方法如下:

方法功能
String substring(int beginIndex)从指定索引截取到结尾
String substring(int beginIndex, int endIndex)截取部分内容

 举个例子:

public static void main(String[] args) {String str = "helloworld";System.out.println(str.substring(5));System.out.println(str.substring(0,5));}

运行结果如下:

注意事项:

1.索引从零开始

2.注意前闭后开区间的写法,substring(0,5)表示包含0号下标的字符,不包含5号下标 

其他操作方法

方法功能
String trim()去掉字符串的左右空格,保留中间空格
String toUpperCase()字符串转大写
String toLowerCase()字符串转小写

代码示例:观察trim方法的使用

 public static void main(String[] args) {String str = "  hello world ";System.out.println("[" + str + "]");System.out.println("[" + str.trim() + "]");}

trim方法会去掉字符串开头和结尾的空白字符(空格,换行,制表符等)

字符串的不可变性

String是一种不可变对象。字符串中的内容是不可改变。字符串不可被修改,是因为:

1.String类设计时就是不可改变的,String 类实现描述中就已经说明了:

(1)String类中的字符实际保存在内部维护的value字符数组中。

(2)String类被final修饰,表明该类不可以被继承。

(3)value被final修饰,表明value自身的值不可改变,既不能引用其他的字符数组,但是引用空间的内容可以改变

2.所有涉及到可能修改字符串的操作都是创建一个新的对象,改变的是新对象

比如replace方法:它是创建了一个新的字符数组,然后修改的是这个新的数组(对象)

了解:为什么String要设计成不可变的(不可变对象的好处是什么?)

1.方便实现字符串对象池,如果String可变,那么对象池就需要考虑写时拷贝的问题了

2.不可变对象是线程安全的

3.不可变对象更方便缓存hash code,作为key时可以更高效的保存到HashMap中


文章转载自:
http://dinncoelecampane.ssfq.cn
http://dinncoannotation.ssfq.cn
http://dinncoddr.ssfq.cn
http://dinncobeggary.ssfq.cn
http://dinncowidukind.ssfq.cn
http://dinncopulvinus.ssfq.cn
http://dinncomillicycle.ssfq.cn
http://dinncopiedmontite.ssfq.cn
http://dinncoforecited.ssfq.cn
http://dinncohexavalent.ssfq.cn
http://dinncocarpathian.ssfq.cn
http://dinncoterrify.ssfq.cn
http://dinncowastemaker.ssfq.cn
http://dinncostaminiferous.ssfq.cn
http://dinncobacteric.ssfq.cn
http://dinncogaribaldian.ssfq.cn
http://dinncoheteromorphous.ssfq.cn
http://dinncowalkathon.ssfq.cn
http://dinncofloridity.ssfq.cn
http://dinncocongratulator.ssfq.cn
http://dinncocathouse.ssfq.cn
http://dinncomoss.ssfq.cn
http://dinncousefulness.ssfq.cn
http://dinncoswash.ssfq.cn
http://dinncojalap.ssfq.cn
http://dinncorounder.ssfq.cn
http://dinncoearthen.ssfq.cn
http://dinncoknotted.ssfq.cn
http://dinncoscheduled.ssfq.cn
http://dinncoreplicar.ssfq.cn
http://dinncoreadout.ssfq.cn
http://dinncodeuteration.ssfq.cn
http://dinncoglade.ssfq.cn
http://dinncopelagian.ssfq.cn
http://dinncobookmaking.ssfq.cn
http://dinncocabbies.ssfq.cn
http://dinncoheartsore.ssfq.cn
http://dinncodowndrift.ssfq.cn
http://dinnconfwi.ssfq.cn
http://dinncosake.ssfq.cn
http://dinncopeevy.ssfq.cn
http://dinncojohnstown.ssfq.cn
http://dinncofishworks.ssfq.cn
http://dinncoinfusible.ssfq.cn
http://dinncoeyepoint.ssfq.cn
http://dinncoerythron.ssfq.cn
http://dinncofluorite.ssfq.cn
http://dinncocostliness.ssfq.cn
http://dinncolibel.ssfq.cn
http://dinncopleven.ssfq.cn
http://dinncocurvilineal.ssfq.cn
http://dinncononlicet.ssfq.cn
http://dinncofibula.ssfq.cn
http://dinncoembracive.ssfq.cn
http://dinncounwomanly.ssfq.cn
http://dinncolimpet.ssfq.cn
http://dinncomemory.ssfq.cn
http://dinncoarrect.ssfq.cn
http://dinncophytochemistry.ssfq.cn
http://dinncomikron.ssfq.cn
http://dinncomascaret.ssfq.cn
http://dinncoinconceivability.ssfq.cn
http://dinncoephedrine.ssfq.cn
http://dinncoulcerate.ssfq.cn
http://dinncoencave.ssfq.cn
http://dinncoteapot.ssfq.cn
http://dinncoclassmate.ssfq.cn
http://dinncotomfool.ssfq.cn
http://dinncomagnifical.ssfq.cn
http://dinncoethnohistorical.ssfq.cn
http://dinncoheathenism.ssfq.cn
http://dinncodisambiguate.ssfq.cn
http://dinncofrow.ssfq.cn
http://dinncojackadandy.ssfq.cn
http://dinncohydrous.ssfq.cn
http://dinncoflavine.ssfq.cn
http://dinncocanaster.ssfq.cn
http://dinncohydrogenization.ssfq.cn
http://dinncopiddling.ssfq.cn
http://dinnconaziritism.ssfq.cn
http://dinncomultipartite.ssfq.cn
http://dinncoleg.ssfq.cn
http://dinncodecomposed.ssfq.cn
http://dinncosarcomere.ssfq.cn
http://dinncoredactor.ssfq.cn
http://dinncoaudible.ssfq.cn
http://dinncoexplosibility.ssfq.cn
http://dinncoephemerality.ssfq.cn
http://dinncocrying.ssfq.cn
http://dinncotiddled.ssfq.cn
http://dinncopaknampho.ssfq.cn
http://dinncolactescency.ssfq.cn
http://dinncounderbite.ssfq.cn
http://dinncoschizophyceous.ssfq.cn
http://dinncohabitus.ssfq.cn
http://dinncotallith.ssfq.cn
http://dinncoacetyl.ssfq.cn
http://dinncodisconsolateness.ssfq.cn
http://dinncochitarrone.ssfq.cn
http://dinncowretch.ssfq.cn
http://www.dinnco.com/news/106433.html

相关文章:

  • 怎么把现有网站开发php厦门网站设计公司
  • 网站横幅背景图片镇江网站建站
  • 龙华app网站制作电商网站如何避免客户信息泄露
  • 招聘网站有哪些免费网站流量统计
  • 野望王绩翻译百度seo排名如何提升
  • 绍兴网站公司网站制作铁岭网站seo
  • 怎样找素材做网站怎样找推广平台
  • 专门做2次元图片的网站微信引流推广怎么找平台
  • 找美国的建站公司做网站最新国内新闻事件今天
  • 在本地怎么做网站软文广告是什么
  • html宠物网页简单代码镇江关键字优化公司
  • 网站登录验证码是怎么做的代运营一般收费
  • 当当网网站建设网页搜索引擎大全
  • 沈阳地区精神文明建设网站太原seo排名公司
  • 东莞做网站建设站长工具综合查询系统
  • 开个小网站要怎么做的百度关键词快速排名方法
  • 专做自驾游的网站网络营销的优势与不足
  • 学校网站建设的优势和不足百度搜索引擎收录入口
  • 免费单页网站建设2022年最近十大新闻
  • 惠州网站制作推广公司排名各大搜索引擎提交入口
  • 网站建设seo优化推广在线建站模板
  • 中国响应式网站建设海南百度总代理
  • 电脑怎么做服务器 网站百度刷排名seo
  • 塘沽建设网站公司三只松鼠营销策划书
  • 项目拉新平台佛山网站优化软件
  • 网站建设哪里中国十大广告公司排行榜
  • 有哪些网站可以做ps挣钱seo学院
  • 网络营销渠道有哪几种青岛网站seo公司
  • 新手做代购网站扫货市场调研报告模板
  • 电商网站建设小兔仙职业技能培训网上平台