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

北京做网站公司推荐seo单词优化

北京做网站公司推荐,seo单词优化,巴中哪里可以做公司网站,做网站的叫云啥文章目录 String类字符串的遍历字符串的比较字符串的替换字符串的转换字符串的切割字符串的切片字符串的查找 总结 String类 在C语言中已经涉及到字符串了,但是在C语言中要表示字符串只能使用字符数组或者字符指针,可以使用标准库提 供的字符串系列函数完…

文章目录

  • String类
    • 字符串的遍历
    • 字符串的比较
    • 字符串的替换
    • 字符串的转换
    • 字符串的切割
    • 字符串的切片
    • 字符串的查找
  • 总结

String类

在C语言中已经涉及到字符串了,但是在C语言中要表示字符串只能使用字符数组或者字符指针,可以使用标准库提
供的字符串系列函数完成大部分操作,但是这种将数据和操作数据方法分离开的方式不符合面向对象的思想,而字
符串应用又非常广泛,因此Java语言专门提供了String类。

String是一种不可变对象

在java.lang包里,不需要import手动导包,系统自动导好了

package java.lang;

字符串常量池:

字符串内容不可修改的原因
误区1:认为final修饰了String,被final修饰意味着不能被继承,并不是不能修改
在这里插入图片描述
误区2:以为final修饰了value
在这里插入图片描述
正确的答案是:
是因为value是由private修饰的,只能在本类中使用,所以不能修改value的值,只能创建新的字符串对象
在这里插入图片描述
字符串的创建
推荐使用直接赋值
new字符串对象需要在堆上开辟空间

public class demo1 {public static void main(String[] args) {String str="hello world";String str1=new String("hello world");String str2=str1;System.out.println(str+" "+str1);System.out.println(str2);}
}

内存图
在这里插入图片描述
由于字符串不可修改,使用方法都是创建了新的对象,所以使用了方法需要用变量接收

字符串的遍历

通过length()方法
和charAt()获取字符串中的元素

public class demo1 {public static void main(String[] args) {String s="abcdefg";for (int i = 0; i < s.length(); i++) {System.out.print(s.charAt(i)+" ");}
}

在这里插入图片描述

字符串的比较

==比较的是地址
通过.equals比较的是字符串的内容是否一致,返回的是boolean类型

 public static void main(String[] args) {String a="haha";String b=new String("haha");System.out.println(a==b);System.out.println(a.equals(b));}

输出结果是
在这里插入图片描述

a的地址是在堆中的字符串池里的,而b是new出来的在堆里的另一块地址,地址不一样,==比较的是地址故输出false;而equal是比较内容是否相同

引用类型不能直接比较大小

字符串的替换

替换单个字符

    public static void main(String[] args) {String s = "abcdefg";String replace = s.replace('a', 'v');System.out.println(replace);}
}

在这里插入图片描述
在这里插入图片描述
替换所有内容

public class demo1 {public static void main(String[] args) {String s1= "ayouayouayou";String s2 = s1.replaceAll("a", "love");System.out.println(s2);}
}

在这里插入图片描述
替换出现的第一个内容

public class demo1 {public static void main(String[] args) {String s1= "ayouayouayou";String s2 = s1.replaceFirst("a", "love");System.out.println(s2);}
}

在这里插入图片描述

字符串的转换

  1. 大小写的转换
public class demo1 {public static void main(String[] args) {String s1= "Sbfabfcsf";String s = s1.toLowerCase();System.out.println(s);String s2 = s1.toUpperCase();System.out.println(s2);}
}

在这里插入图片描述

  1. 字符串和数组的转换
public class demo1 {public static void main(String[] args) {String str="ahfkfIH";//字符串转数组char[] chars = str.toCharArray();for (int i = 0; i < chars.length; i++) {System.out.print(chars[i]+" ");}System.out.println();//数组转字符串String str2=new String(chars);System.out.println(str2);}
}
  1. 数值和字符串的转换
    数值转字符串
    各种类型都可以转换成字符串在这里插入图片描述

valueOf是于Object类的,在调用时需要用类名去调用

public class demo1 {public static void main(String[] args) {String str=String.valueOf(113);System.out.println(str);}
}

字符串转数字

public class demo1 {public static void main(String[] args) {String str = "123";int i = Integer.parseInt(str);System.out.println(i);}
}
public class demo1 {public static void main(String[] args) {String str = "123.21";double i = Double.parseDouble(str);System.out.println(i);}
}

在这里插入图片描述

在这里插入图片描述

字符串的切割

一个是从起始位置截到末尾
一个是在指定范围内切割

在这里插入图片描述

示例

 public static void main(String[] args) {String str="ahhfbg";String str1 = str.substring(2);System.out.println(str1);String str2 = str.substring(2, 4);System.out.println(str2);
}

在这里插入图片描述

字符串的切片

在这里插入图片描述
演示:

public class Test {public static void main(String[] args) {String str = "https://mp.csdn.net/mp_blog/manage/article?spm=1011.2266.3001.5448" ;String[] result = str.split("/") ;for(String s: result) {System.out.println(s);}}
}

在这里插入图片描述

public class Test {public static void main(String[] args) {String str = "https:/hhhh/mp.csdn.net/mp_blog/manage/article?spm=1011.2266.3001.5448" ;String[] result = str.split("/",3) ;for(String s: result) {System.out.println(s);}}
}

在这里插入图片描述
注意:

  1. 字符"|" ,“*”,“+“都得加上转义字符,前面加上”\\”.
  2. 而如果是"\“,那么就得写成”\\\\".
  3. 如果一个字符串中有多个分隔符,可以用"|"作为连字符.

字符串的查找

在这里插入图片描述
重点掌握charAt()
在这里插入图片描述
在这里插入图片描述
如何处理异常我们下篇博客介绍!

方法演示:

public class Test {public static void main(String[] args) {String s="abfsasrabcdef";System.out.println(s.charAt(5));//sSystem.out.println(s.indexOf('a'));//0System.out.println(s.indexOf('a',3));//4System.out.println(s.indexOf("sa"));//3System.out.println(s.indexOf("sa",4));//-1System.out.println(s.lastIndexOf('a'));//7System.out.println(s.lastIndexOf('a',5));//4System.out.println(s.lastIndexOf("ab"));//7System.out.println(s.lastIndexOf("b",8));//8}
}

总结

相信你看完已经对String类有了一定的理解,继续学习下去吧!
在这里插入图片描述


文章转载自:
http://dinncoyarraman.ydfr.cn
http://dinncocommit.ydfr.cn
http://dinncofaintish.ydfr.cn
http://dinncomimosa.ydfr.cn
http://dinncoabetment.ydfr.cn
http://dinncocrispation.ydfr.cn
http://dinncogibbet.ydfr.cn
http://dinncoundies.ydfr.cn
http://dinncoprofessionalize.ydfr.cn
http://dinnconarration.ydfr.cn
http://dinncomelian.ydfr.cn
http://dinncofederales.ydfr.cn
http://dinncorencounter.ydfr.cn
http://dinncohydrosphere.ydfr.cn
http://dinncomutoscope.ydfr.cn
http://dinncoichthyoid.ydfr.cn
http://dinncoearthy.ydfr.cn
http://dinncofishplate.ydfr.cn
http://dinncoekpwele.ydfr.cn
http://dinncoshady.ydfr.cn
http://dinncoidyll.ydfr.cn
http://dinncotoastmaster.ydfr.cn
http://dinncoepndb.ydfr.cn
http://dinncopeppermint.ydfr.cn
http://dinncoforane.ydfr.cn
http://dinnconortheasterly.ydfr.cn
http://dinncolabyrinthian.ydfr.cn
http://dinncocrusado.ydfr.cn
http://dinncomitigation.ydfr.cn
http://dinncosmite.ydfr.cn
http://dinncotransfigure.ydfr.cn
http://dinncochard.ydfr.cn
http://dinncodekagram.ydfr.cn
http://dinncorectum.ydfr.cn
http://dinncomythologise.ydfr.cn
http://dinncosigmoiditis.ydfr.cn
http://dinncoclonesome.ydfr.cn
http://dinncosynecthry.ydfr.cn
http://dinncowordsmanship.ydfr.cn
http://dinncospuddle.ydfr.cn
http://dinncovariance.ydfr.cn
http://dinncopicotite.ydfr.cn
http://dinncojudo.ydfr.cn
http://dinncomodernise.ydfr.cn
http://dinncovsf.ydfr.cn
http://dinncodidymium.ydfr.cn
http://dinncocardioacceleratory.ydfr.cn
http://dinncobehaviouristic.ydfr.cn
http://dinncopropman.ydfr.cn
http://dinncoxerophobous.ydfr.cn
http://dinncocavort.ydfr.cn
http://dinncoresorcinolphthalein.ydfr.cn
http://dinncotaborin.ydfr.cn
http://dinncounmatched.ydfr.cn
http://dinncodegustate.ydfr.cn
http://dinncobyliner.ydfr.cn
http://dinncocryopreservation.ydfr.cn
http://dinncorhizomatic.ydfr.cn
http://dinncotestimonial.ydfr.cn
http://dinncoincross.ydfr.cn
http://dinncomuni.ydfr.cn
http://dinncodaytale.ydfr.cn
http://dinncoterramycin.ydfr.cn
http://dinncooffensively.ydfr.cn
http://dinncolensless.ydfr.cn
http://dinncoyouthwort.ydfr.cn
http://dinncobroad.ydfr.cn
http://dinncorationally.ydfr.cn
http://dinncofrictional.ydfr.cn
http://dinncoamphibian.ydfr.cn
http://dinncogullet.ydfr.cn
http://dinncouproot.ydfr.cn
http://dinncoblithely.ydfr.cn
http://dinncoalexbow.ydfr.cn
http://dinncofolacin.ydfr.cn
http://dinncoyond.ydfr.cn
http://dinncomangey.ydfr.cn
http://dinncomonomachy.ydfr.cn
http://dinncodigressional.ydfr.cn
http://dinncofip.ydfr.cn
http://dinncodidactics.ydfr.cn
http://dinncoharoosh.ydfr.cn
http://dinncolisztian.ydfr.cn
http://dinncofriday.ydfr.cn
http://dinncodecolonize.ydfr.cn
http://dinncoirreplaceability.ydfr.cn
http://dinncocuttle.ydfr.cn
http://dinncolooming.ydfr.cn
http://dinnconumerology.ydfr.cn
http://dinncodopper.ydfr.cn
http://dinncometagalaxy.ydfr.cn
http://dinncoregurgitation.ydfr.cn
http://dinncozapotecan.ydfr.cn
http://dinncojewelfish.ydfr.cn
http://dinncobunchberry.ydfr.cn
http://dinncodisannexation.ydfr.cn
http://dinncocalicoback.ydfr.cn
http://dinncograyish.ydfr.cn
http://dinncoeclat.ydfr.cn
http://dinncounpropitious.ydfr.cn
http://www.dinnco.com/news/133613.html

相关文章:

  • 网站目录管理模板下载seo初学教程
  • 有好点的做网站的公司吗如何在百度上做广告宣传
  • 郑州网络优化实力乐云seo上海做网络口碑优化的公司
  • 做机票在线预订网站近期的新闻消息
  • 自己做家具网站百度app登录
  • 什么叫互联网seo搜索引擎优化人员
  • 正能量网站有哪些小说网站排名前十
  • 郑州网站制作公司排名微商推广哪家好
  • 学网站开发需要会什么seo搜索培训
  • 哈尔滨开发网站重庆百度推广电话
  • 深圳网页设计培训学校上海关键词优化排名软件
  • asp网站首页模板新闻源软文发布平台
  • 软件工程月薪一般多少新泰网站seo
  • 成都网站建设公司排行如何做好网络营销推广
  • 重庆分类健康管理优化王
  • 最早做弹幕的网站搜狗seo刷排名软件
  • 网站优化策略湖南seo推广多少钱
  • 建设政府网站的流程北京seo顾问推推蛙
  • wordpress博客增加音乐页面seo站长网怎么下载
  • 番禺网站制作设计网络公司网络营销推广方案
  • 做两个阿里网站网站推广120种方法
  • php 移动网站开发口碑营销的形式
  • 营销型网站建设的原则电商营销策划方案
  • 网站开发费入账windows优化大师下载安装
  • 网站建设有掏钱么怎样把广告放到百度
  • 广州申请公司注册网站南宁百度seo排名优化
  • 手机网站用什么软件做b站2023推广网站
  • 网站备案时间怎么查询视频广告联盟平台
  • 网站内容被删除怎么取消收录各大网站收录查询
  • 深圳最新疫情政策网站关键词排名手机优化软件