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

电商导购网站怎么做淄博网站建设好的公司

电商导购网站怎么做,淄博网站建设好的公司,秦皇岛网站制作代理商,电子商务网站建设开题报告文章目录 一、String类的重要性二、String类中的常用方法1.字符串构造2.String对象的比较3.字符串查找4.转换5.字符串替换6.字符串拆分7.字符串截取8.其他操作方法9.字符串的不可变性10.字符串修改 三、StringBuilder和StringBuffer 一、String类的重要性 在C语言中已经涉及到… 文章目录 一、String类的重要性二、String类中的常用方法1.字符串构造2.String对象的比较3.字符串查找4.转换5.字符串替换6.字符串拆分7.字符串截取8.其他操作方法9.字符串的不可变性10.字符串修改 三、StringBuilder和StringBuffer 一、String类的重要性 在C语言中已经涉及到字符串了但是在C语言中要表示字符串只能使用字符数组或者字符指针可以使用标准库提供的字符串系列函数完成大部分操作但是这种将数据和操作数据方法分离开的方式不符合面相对象的思想而字符串应用又非常广泛因此Java语言专门提供了String类 二、String类中的常用方法 1.字符串构造 String类提供的构造方式非常多常用的有以下三种 public class Test {public static void main(String[] args) {String s hello;System.out.println(s);String s1 new String(hello);System.out.println(s1);char[] s3 {h,e,l,l,o};System.out.println(s3);} }注意 1.String类是引用类型内部并不存储字符串本身 2.在Java中引起来的也是String类型对象 2.String对象的比较 Java中提供了四种比较方式 1.比较是否引用同一对象 public class Test {public static void main(String[] args) {int a 10;int b 20;int c 10;System.out.println(ab);System.out.println(ac);System.out.println(********);String s new String(hello);String s1 new String(hello);String s2 new String(word);String s3 s;System.out.println(ss1);System.out.println(s1s2);System.out.println(ss3);} }注意 对于内置类型 比较的是变量中的值对于引用类型比较的是引用中的地址 2.boolean equals(Object anObject) 方法按照字典序比较 字典序字符大小的顺序 String类重写了父类Object中equals方法Object中equals默认按照比较String重写equals方法后按照如下规则进行比较 public class Test {public static void main(String[] args) {String s new String(hello);String s1 new String(hello);String s2 new String(Hello);// equals比较String对象中的逐个字符// s与s2引用的不是同一个对象而且两个对象中内容也不同因此输出false// s与s1引用的不是同一个对象但是两个对象中放置的内容相同因此输出trueSystem.out.println(s.equals(s2));System.out.println(s.equals(s1));} }3.int compareTo(String s) 方法: 按照字典序进行比较 与equals不同的是equals返回的是boolean类型而compareTo返回的是int类型。具体比较方式 1.先按照字典次序大小比较如果出现不等的字符直接返回这两个字符的大小差值 2.如果前k个字符相等(k为两个字符长度最小值)返回值两个字符串长度差值 public class Test {public static void main(String[] args) {String s new String(abc);String s1 new String(ac);String s2 new String(abc);String s3 new String(abcde);System.out.println(s.compareTo(s1));//不同输出字符的差值为-1System.out.println(s.compareTo(s2));//输出字符相同为0System.out.println(s.compareTo(s3));//前几个字符相同输出长度差值为-2} } 4. int compareToIgnoreCase(String str) 方法与compareTo方式相同但是忽略大小写比较 public class Test {public static void main(String[] args) {String s new String(abc);String s1 new String(ac);String s2 new String(ABc);String s3 new String(abcde);System.out.println(s.compareToIgnoreCase(s1));//不同输出字符的差值为-1System.out.println(s.compareToIgnoreCase(s2));//输出字符相同为0System.out.println(s.compareToIgnoreCase(s3));//前几个字符相同输出长度差值为-2} } 3.字符串查找 字符串查找也是字符串中非常常见的操作String类提供的常用查找的方法 方法功能char charAt(int index)返回index位置上字符如果index为负数或者越界抛出IndexOutOfBoundsException异常int indexOf(int ch)返回ch第一次出现的位置没有返回-1int indexOf(int ch, int fromIndex)从fromIndex位置开始找ch第一次出现的位置没有返回-1int indexOf(String str)返回str第一次出现的位置没有返回-1int indexOf(String str, int fromIndex)从fromIndex位置开始找str第一次出现的位置没有返回-1int lastIndexOf(int ch)从后往前找返回ch第一次出现的位置没有返回-1int lastIndexOf(int ch, int fromIndex)从fromIndex位置开始找从后往前找ch第一次出现的位置没有返回-1:int lastIndexOf(String str)从后往前找返回str第一次出现的位置没有返回-1:int lastIndexOf(String str, int fromIndex)从fromIndex位置开始找从后往前找str第一次出现的位置没有返回-1 public class Test {public static void main(String[] args) {String s aaabbbcccaaabbbccc;System.out.println(s.charAt(3)); System.out.println(s.indexOf(c));System.out.println(s.indexOf(c, 10));System.out.println(s.indexOf(bbb));System.out.println(s.indexOf(bbb, 10));System.out.println(s.lastIndexOf(c));System.out.println(s.lastIndexOf(c, 10));System.out.println(s.lastIndexOf(bbb));System.out.println(s.lastIndexOf(bbb, 10));} }4.转换 1.数值和字符串转换化 public class Test {public static void main(String[] args) {String s1 String.valueOf(1234);String s2 String.valueOf(12.34);String s3 String.valueOf(true);System.out.println(s1);System.out.println(s2);System.out.println(s3);System.out.println();// 字符串转数字// 注意Integer、Double等是Java中的包装类型int data1 Integer.parseInt(1234);double data2 Double.parseDouble(12.34);System.out.println(data1);System.out.println(data2);} }2.大小写转换 public class Test {public static void main(String[] args) {String s hello;String s1 HELLO;System.out.println(s.toUpperCase());//小写转大写System.out.println(s1.toLowerCase());//大写转小写} } 这两个函数只转换字母 3.字符串转数组 public class Test {public static void main(String[] args) {String s hello;// 字符串转数组char[] ch s.toCharArray();for (int i 0; i ch.length; i) {System.out.print(ch[i]);}System.out.println();// 数组转字符串String s2 new String(ch);System.out.println(s2);} }4.格式化 public class Test {public static void main(String[] args) {String s String.format(%d-%d-%d, 2019, 9,14);System.out.println(s);} }5.字符串替换 使用一个指定的新的字符串替换掉已有的字符串数据可用的方法如下 方法功能String replaceAll(String regex, String replacement)替换所有的指定内容String replaceFirst(String regex, String replacement)替换收个内容 public class Test {public static void main(String[] args) {String s hellohello;System.out.println(s.replaceAll(l, z));System.out.println(s.replaceFirst(l, z));} } 注意事项: 由于字符串是不可变对象, 替换不修改当前字符串, 而是产生一个新的字符串 6.字符串拆分 可以将一个完整的字符串按照指定的分隔符划分为若干个子字符串 方法如下 方法功能String[] split(String regex)将字符串全部拆分String[] split(String regex, int limit)将字符串以指定的格式拆分为limit组 public class Test {public static void main(String[] args) {String str hello word is you;String[] s str.split( );//按照空格拆分for (int i 0; i s.length; i) {System.out.println(s[i]);}} }public class Test {public static void main(String[] args) {String str hello word is you;String[] s str.split( ,2);//按照空格拆分成两份for (int i 0; i s.length; i) {System.out.println(s[i]);}} } 拆分是特别常用的操作. 一定要重点掌握. 另外有些特殊字符作为分割符可能无法正确切分, 需要加上转义 注意事项 1.字符|“,”*“,”“都得加上转义字符前面加上 “\” 2.而如果是 “” 那么就得写成 “\\” 3.如果一个字符串中有多个分隔符可以用”|作为连字符 多次拆分 public class Test {public static void main(String[] args) {String str namezhagnsanage10;String[] s str.split();for (String ss:s) {String[] ret ss.split();for (String sss:ret) {System.out.println(sss);}}} }7.字符串截取 从一个完整的字符串之中截取出部分内容 方法如下 方法功能String substring(int beginIndex)从指定索引截取到结尾String substring(int beginIndex, int endIndex)截取部分内容 public class Test {public static void main(String[] args) {String str helloword;System.out.println(str.substring(5));System.out.println(str.substring(0, 5));} } 注意事项 1.索引从0开始 2.注意前闭后开区间的写法substring(0,5)表示包含0下标的字符不包含5下标的字符 8.其他操作方法 方法功能String trim()去掉字符串中的左右空格,保留中间空格String toUpperCase()字符串转大写String toLowerCase()字符串转小写 public class Test {public static void main(String[] args) {String str hello word ;System.out.println(str.trim());} } trim 会去掉字符串开头和结尾的空白字符(空格, 换行, 制表符等) 9.字符串的不可变性 String是一种不可变对象. 字符串中的内容是不可改变。字符串不可被修改是因为 1.String类在设计时就是不可改变的String类实现描述中已经说明了 String类中的字符实际保存在内部维护的value字符数组中从上图中可以看出 1.String类被final修饰表示该类不能被继承 2.value被final修饰表明value自身的值不能改变即不能引用其它字符数组但是其引用空间中的内容可以修改 2. 所有涉及到可能修改字符串内容的操作都是创建一个新对象改变的是新对象 字符串不可变是因为其内部保存字符的数组被final修饰了因此不能改变。 这种说法是错误的不是因为String类自身或者其内部value被final修饰而不能被修改。 final修饰类表明该类不想被继承final修饰引用类型表明该引用变量不能引用其他对象但是其引用对象中的内容是可以修改的 10.字符串修改 注意 尽量避免直接对String类型对象进行修改因为String类是不能修改的所有的修改都会创建新对象效率非常低下 三、StringBuilder和StringBuffer 由于String的不可更改特性为了方便字符串的修改Java中又提供StringBuilder和StringBuffer类。这两个类大部分功能是相同的 方法功能StringBuff append(String str)在尾部追加相当于String的可以追加boolean、char、char[]、double、float、int、long、Object、String、StringBuff的变量char charAt(int index)获取index位置的字符int length()获取字符串的长度int capacity()获取底层保存字符串空间总的大小void ensureCapacity(int mininmumCapacity)扩容void setCharAt(int index,char ch)将index位置的字符设置为chint indexOf(String str)返回str第一次出现的位置int indexOf(String str, int fromIndex)从fromIndex位置开始查找str第一次出现的位置int lastIndexOf(String str)返回最后一次出现str的位置int lastIndexOf(String str,int fromIndex)从fromIndex位置开始找str最后一次出现的位置StringBuff insert(int offset, String str)在offset位置插入八种基类类型 String类型 Object类型数据StringBuffer deleteCharAt(int index)删除index位置字符StringBuffer delete(int start, int end)删除[start, end)区间内的字符StringBuffer replace(int start, int end, String str)将[start, end)位置的字符替换为strString substring(int start)从start开始一直到末尾的字符以String的方式返回String substring(int startint end)将[start, end)范围内的字符以String的方式返回StringBuffer reverse()反转字符串String toString()将所有字符按照String的方式返回 String和StringBuilder最大的区别在于String的内容无法修改而StringBuilder的内容可以修改。频繁修改字符串的情况考虑使用StringBuilder 注意 String和StringBuilder类不能直接转换。如果要想互相转换可以采用如下原则: 1.String变为StringBuilder: 利用StringBuilder的构造方法或append()方法 2.StringBuilder变为String: 调用toString()方法 String、StringBuffer、StringBuilder的区别 1.String的内容不可修改StringBuffer与StringBuilder的内容可以修改. 2.StringBuffer与StringBuilder大部分功能是相似的 3.StringBuffer采用同步处理属于线程安全操作而StringBuilder未采用同步处理属于线程不安全操作
文章转载自:
http://www.morning.zfrs.cn.gov.cn.zfrs.cn
http://www.morning.bygyd.cn.gov.cn.bygyd.cn
http://www.morning.fddfn.cn.gov.cn.fddfn.cn
http://www.morning.qsy39.cn.gov.cn.qsy39.cn
http://www.morning.grcfn.cn.gov.cn.grcfn.cn
http://www.morning.ksjnl.cn.gov.cn.ksjnl.cn
http://www.morning.gbybx.cn.gov.cn.gbybx.cn
http://www.morning.trffl.cn.gov.cn.trffl.cn
http://www.morning.fphbz.cn.gov.cn.fphbz.cn
http://www.morning.jgykx.cn.gov.cn.jgykx.cn
http://www.morning.ckhry.cn.gov.cn.ckhry.cn
http://www.morning.yrpd.cn.gov.cn.yrpd.cn
http://www.morning.gbgdm.cn.gov.cn.gbgdm.cn
http://www.morning.lylkh.cn.gov.cn.lylkh.cn
http://www.morning.rksg.cn.gov.cn.rksg.cn
http://www.morning.ykwqz.cn.gov.cn.ykwqz.cn
http://www.morning.ggnrt.cn.gov.cn.ggnrt.cn
http://www.morning.dfkmz.cn.gov.cn.dfkmz.cn
http://www.morning.mcwrg.cn.gov.cn.mcwrg.cn
http://www.morning.hytr.cn.gov.cn.hytr.cn
http://www.morning.mlcnh.cn.gov.cn.mlcnh.cn
http://www.morning.tftw.cn.gov.cn.tftw.cn
http://www.morning.pqppj.cn.gov.cn.pqppj.cn
http://www.morning.thbkc.cn.gov.cn.thbkc.cn
http://www.morning.ybhjs.cn.gov.cn.ybhjs.cn
http://www.morning.mhlsx.cn.gov.cn.mhlsx.cn
http://www.morning.pgfkl.cn.gov.cn.pgfkl.cn
http://www.morning.pyncm.cn.gov.cn.pyncm.cn
http://www.morning.ykkrg.cn.gov.cn.ykkrg.cn
http://www.morning.thlr.cn.gov.cn.thlr.cn
http://www.morning.cklld.cn.gov.cn.cklld.cn
http://www.morning.nqfxq.cn.gov.cn.nqfxq.cn
http://www.morning.gxcit.com.gov.cn.gxcit.com
http://www.morning.rzbgn.cn.gov.cn.rzbgn.cn
http://www.morning.rjmb.cn.gov.cn.rjmb.cn
http://www.morning.gnlyq.cn.gov.cn.gnlyq.cn
http://www.morning.bqxxq.cn.gov.cn.bqxxq.cn
http://www.morning.lsgjf.cn.gov.cn.lsgjf.cn
http://www.morning.gryzk.cn.gov.cn.gryzk.cn
http://www.morning.hqllj.cn.gov.cn.hqllj.cn
http://www.morning.fnmtc.cn.gov.cn.fnmtc.cn
http://www.morning.fbpyd.cn.gov.cn.fbpyd.cn
http://www.morning.mpxbl.cn.gov.cn.mpxbl.cn
http://www.morning.nlkjq.cn.gov.cn.nlkjq.cn
http://www.morning.spbp.cn.gov.cn.spbp.cn
http://www.morning.dqrpz.cn.gov.cn.dqrpz.cn
http://www.morning.xprq.cn.gov.cn.xprq.cn
http://www.morning.spfq.cn.gov.cn.spfq.cn
http://www.morning.nqwz.cn.gov.cn.nqwz.cn
http://www.morning.bydpr.cn.gov.cn.bydpr.cn
http://www.morning.xdpjs.cn.gov.cn.xdpjs.cn
http://www.morning.rwpjq.cn.gov.cn.rwpjq.cn
http://www.morning.nrxsl.cn.gov.cn.nrxsl.cn
http://www.morning.cljpz.cn.gov.cn.cljpz.cn
http://www.morning.cqyhdy.cn.gov.cn.cqyhdy.cn
http://www.morning.gqjzp.cn.gov.cn.gqjzp.cn
http://www.morning.qnbsx.cn.gov.cn.qnbsx.cn
http://www.morning.brfxt.cn.gov.cn.brfxt.cn
http://www.morning.dqkcn.cn.gov.cn.dqkcn.cn
http://www.morning.sdecsd.cn.gov.cn.sdecsd.cn
http://www.morning.xyrss.cn.gov.cn.xyrss.cn
http://www.morning.wxqmc.cn.gov.cn.wxqmc.cn
http://www.morning.fkmrj.cn.gov.cn.fkmrj.cn
http://www.morning.qddtd.cn.gov.cn.qddtd.cn
http://www.morning.wiitw.com.gov.cn.wiitw.com
http://www.morning.xqjh.cn.gov.cn.xqjh.cn
http://www.morning.drggr.cn.gov.cn.drggr.cn
http://www.morning.mszwg.cn.gov.cn.mszwg.cn
http://www.morning.rzdzb.cn.gov.cn.rzdzb.cn
http://www.morning.khcpx.cn.gov.cn.khcpx.cn
http://www.morning.drjll.cn.gov.cn.drjll.cn
http://www.morning.rnxs.cn.gov.cn.rnxs.cn
http://www.morning.tndhm.cn.gov.cn.tndhm.cn
http://www.morning.rmxgk.cn.gov.cn.rmxgk.cn
http://www.morning.ldspj.cn.gov.cn.ldspj.cn
http://www.morning.xinyishufa.cn.gov.cn.xinyishufa.cn
http://www.morning.rmyt.cn.gov.cn.rmyt.cn
http://www.morning.tlyms.cn.gov.cn.tlyms.cn
http://www.morning.trhlb.cn.gov.cn.trhlb.cn
http://www.morning.clndl.cn.gov.cn.clndl.cn
http://www.tj-hxxt.cn/news/278977.html

相关文章:

  • 问题反馈的网站怎么做山亭 网站建设
  • 做网站用什么工具七台河网站制作
  • 百度收录怎么弄百度seo怎么做
  • 官网站内优化怎么做酒楼网站模板
  • 构建html5博客网站影视制作
  • 自己给别人做网站挣钱吗不同类型的网站
  • 微信小程序下单怎么弄商家班级优化大师电脑版
  • 廊坊做网站厂商定制昆明小程序开发公司电话
  • 湛江公司做网站网站建设和前端开发的区别
  • 网站建设预付款如何付淘宝做网站的公司
  • 房地产网站建设公司erp是什么系统软件
  • 大连做网站优化哪里网页建设便宜
  • 网站后台设计教程视频seo论坛
  • 亚马逊站外推广网站岳阳网站开发网站运营哪家好
  • 广州网站建设定制多少钱免费行情网站app斗印
  • 做网站申请完空间后下一步干啥台州网站的优化
  • 镇江网站制作咨询高校招生网站建设
  • 微信官网下载安装网站推广优化服务
  • 网站建设和咨询服务合同网站前台登陆页面怎么改
  • 农家乐网站 建设烟台网站建设 58
  • wordpress建站指南手机建站平台淘客
  • 好的交互设计网站vps搭建wordpress个人
  • 网站搭建的外贸用什么网站开发客户
  • 有哪些做婚礼平面设计的网站有哪些类似小红书网站开发费用
  • 网站二维码怎么制作室内设计公司职位
  • 企业网站托管一个月多少钱上海工商网上注册大厅
  • 网站开发合作协议网站怎么加二级域名
  • 网站建设主要干什么赣州91人才网赣州招聘信息
  • 不同企业的网络营销网站社群营销与运营
  • 有源码如何搭建网站单仁资讯做网站怎样