手机php网站开发网站托管服务怎么收费

张小明 2026/1/7 11:11:53
手机php网站开发,网站托管服务怎么收费,在哪个网站可以做图文合并,深圳建模板网站String类是Java内置的用来表示字符串的类#xff0c;所有的字面量字符串#xff0c;都是String类的实例实现。当然#xff0c;我们也可以通过new一个新对象的方式#xff0c;创建一个String实例。 public class App { public static void main(String[] args) { // 方式1…String类是Java内置的用来表示字符串的类所有的字面量字符串都是String类的实例实现。当然我们也可以通过new一个新对象的方式创建一个String实例。publicclassApp{publicstaticvoidmain(String[]args){// 方式1使用字面量Strings1hello;// 方式2newStrings2newString(hi);}}需要注意的是使用字面量创建的字符串字符串会存储到内存的字符串常量池中。在Java有所谓“享元模式”共享元素即两个变量如果引用相同的字符串内容系统会指向同一个字符串常量池中内的字符串。证明如下publicclassDemo0{publicstaticvoidmain(String[]args){// 用字面量创建一个String对象Strings1hello;// 用字面量创建另外一个String对象字符串内容完全相同Strings2hello;// 证明两个变量都是同一个对象的引用System.out.println(s1s2);// true}}而如果不是用的字面量是用new创建两个String对象则是完全不同的结果。用new创建两个字符串内容完全相同的String对象会在内存堆里存储对象。两个变量则是完全不同的对象。证明如下publicclassDemo1{publicstaticvoidmain(String[]args){// 用new创建一个String对象Strings1newString(hello);// 用new创建另外一个String对象字符串内容完全相同Strings2newString(hello);// 证明两个变量是两个对象System.out.println(s1s2);// false}}字符串在编程中是最常见的几种对象因此String方法非常非常丰富。String对象是不可变的其方法产生的字符串都是返回一个新的String对象。String常用的方法String类的常见方法可以划分为基本操作、转换操作、替换与去除、截取与分隔、判断操作等分类。String类的基本操作方法有获取字符串长度、返回字符在字符串中第一次、最后一次出现的索引、返回字符串索引上的字符等。publicclassDemo2{publicstaticvoidmain(String[]args){Strings1hello;// 获取字符串的长度System.out.println(s1.length());// 5// 返回字符在字符串中第一次出现的索引System.out.println(s1.indexOf(l));// 2 索引从0开始// 返回字符在字符串中最后一次出现的索引System.out.println(s1.lastIndexOf(l));// 3// 返回指定索引的字符System.out.println(s1.charAt(1));// e}}String类的转换操作有将字符串转换为字符数组、将int类型转换为字符串、将字符串中所有字符转换为小写、将字符串中所有字符转换为大写publicclassDemo3{publicstaticvoidmain(String[]args){Strings1hello;// 将字符串转换为字符数组char[]chss1.toCharArray();for(inti0;ichs.length;i){System.out.print(chs[i]);// hello}System.out.println();// 将int类型转换为字符串inta10086;Strings2String.valueOf(a);System.out.println(s2);// 10086// 将字符串中的字符全部转换为大写Strings3s1.toUpperCase();System.out.println(s3);// HELLO// 将字符串中的字符全部转换为小写Strings4s1.toLowerCase();System.out.println(s4);// hello}}String类的替换去除操作用新字符串替换原有字符串得到一个新的字符串去除字符串首尾的空格。publicclassDemo4{publicstaticvoidmain(String[]args){Strings1hello;// 用新字符串替换原有字符串得到一个新的字符串Strings2s1.replace(hello,helloworld);System.out.println(s2);// helloworld// 去除字符串首尾的空格Strings3 hello ;Strings4s3.trim();// 建议用strip()替代System.out.println(s4);// hello}}需要注意trim()只能去除ASCII码≤32的空白字符空格、制表符、换行等但不能去除全角空格或其他Unicode空白字符。Java 11引入了strip()方法来解决这个问题。因此建议使用strip()方法替代trim()方法String类的截取与分隔操作有根据参数将原字符串分隔为若干个字符串字符串数组、截取从指定索引后的所有字符、截取从指定开始索引到指定结束索引之间的字符。publicclassDemo5{publicstaticvoidmain(String[]args){Strings1this is a text;// 将原字符串分隔为若干个字符串字符串数组String[]arrs1.split( );for(inti0;iarr.length;i){System.out.println(arr[i]);}// 截取从指定索引后的所有字符Strings2helloworld;System.out.println(s2.substring(5));// world// 截取从指定开始索引到指定结束索引之间的字符System.out.println(s2.substring(2,4));// ll}}String类的判断操作有判断与指定字符串比较是否相等、判断字符串是否以指定字符串开始、判断字符串是否以指定字符串结尾、判断字符串是否包含指定的字符序列、判断字符串是否为空字符串长度为0。publicclassDemo6{publicstaticvoidmain(String[]args){Strings1hello;// 判断与指定字符串比较是否相等System.out.println(s1.equals(hello));// true// 判断字符串是否以指定字符串开始System.out.println(s1.startsWith(he));// true// 判断字符串是否以指定字符串结尾System.out.println(s1.endsWith(lo));// true// 判断字符串是否包含指定的字符序列System.out.println(s1.contains(llo));// true// 判断字符串是否为空System.out.println(s1.isEmpty());// false}}StringBuilder和StringBuffer类由于String对象是不可变对象因此String类的所有方法若是返回字符串都是返回一个新的字符串。由于字符串是高频出现的对象而因为字符串的不可变特性对内存的开销较大。因此Java系统前后推出了StringBuffer类和StringBuilder类作为String类的补充。两者都是可变的字符串对象两者的方法都几乎相同都是在原字符串上进行变更修改而不是产生一个新的字符串对象。以StringBuilder为例演示StringBuilder和StringBuffer类的常用方法。publicclassDemo7{publicstaticvoidmain(String[]args){StringBufferstrnewStringBuffer(hello);// append方法添加字符串str.append( world);System.out.println(str);// hello world// insert方法在指定位置添加字符串str.insert(5, javas);System.out.println(str);// hello javas world// replace方法替换字符串str.replace(5,12, java);System.out.println(str);// hello java world// delete方法删除字符串str.delete(5,10);System.out.println(str);// hello world}}StringBuffer类和StringBuilder类区别在于相对运行快慢和线程安全性StringBuffer是线程安全的运行性能比StringBuilder慢。而StringBuilder虽然是线程不安全的但是优势在于运行速度快。packagestring.demo2;publicclassDemo7{publicstaticvoidmain(String[]args){StringBufferstr0newStringBuffer(hello);StringBuilderstr1newStringBuilder(hello);// 测试StringBuffer对象方法的运行时间longstartSystem.nanoTime();// append方法添加字符串str0.append( world);System.out.println(str0);// hello world// insert方法在指定位置添加字符串str0.insert(5, javas);System.out.println(str0);// hello javas world// replace方法替换字符串str0.replace(5,12, java);System.out.println(str0);// hello java world// delete方法删除字符串str0.delete(5,10);System.out.println(str0);// hello worldlongendSystem.nanoTime();System.out.println(StringBuffer运行时间(end-start)纳秒);System.out.println(------------------------------------------------);// 测试StringBuilder对象方法的运行时间longstart1System.nanoTime();str1.append( world);System.out.println(str1);str1.insert(5, javas);System.out.println(str1);str1.replace(5,12, java);System.out.println(str1);str1.delete(5,10);System.out.println(str1);longend1System.nanoTime();System.out.println(StringBuilder运行时间(end1-start1)纳秒);}}hello world hello javas world hello java world hello world StringBuffer运行时间398609纳秒 ------------------------------------------------ hello world hello javas world hello java world hello world StringBuilder运行时间92160纳秒 进程已结束退出代码为0由此可见StringBuilder确实要更快一些。一般情况下我们都是单线程运行程序因此推荐用StringBuilder。
版权声明:本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!

百度站长工具综合查询wordpress教育插件

🔥作者简介: 一个平凡而乐于分享的小比特,中南民族大学通信工程专业研究生,研究方向无线联邦学习 🎬擅长领域:驱动开发,嵌入式软件开发,BSP开发 ❄️作者主页:一个平凡而…

张小明 2026/1/7 7:57:56 网站建设

做it的中国企业网站网站编辑有前途吗

深蓝词库转换:输入法词库格式不兼容的终极解决方案 【免费下载链接】imewlconverter ”深蓝词库转换“ 一款开源免费的输入法词库转换程序 项目地址: https://gitcode.com/gh_mirrors/im/imewlconverter 还在为不同输入法之间的词库无法通用而烦恼吗&#xf…

张小明 2026/1/7 7:23:27 网站建设

怎么做淘宝一样的网站我的电脑做网站服务器吗

设计模式深度解析:适配器、桥接与责任链模式 在软件开发中,设计模式是解决常见问题的有效手段。本文将深入探讨适配器模式、桥接模式和责任链模式,介绍它们的原理、实现和应用场景。 1. 适配器模式 适配器模式是一种结构型设计模式,用于将一个类的接口转换成客户希望的另…

张小明 2026/1/7 7:29:51 网站建设

注册个网站要多少钱鹿泉区城乡建设局网站

FaceFusion能否用于艺术创作?数字肖像画新范式 在当代艺术与技术交汇的前沿,一个有趣的问题正在浮现:当AI不仅能识别人脸,还能“重写”人脸时,它是否也能成为艺术家手中的画笔?这不是关于替代人类创造力的担…

张小明 2026/1/7 8:05:48 网站建设

网站域名查询系统做网站 报价 需要了解

从零开始的挑战与机遇 作为一名空降的测试团队领导,我在2024年初接手时,团队正面临诸多困境:测试流程松散,自动化覆盖率低,成员士气低迷,项目交付频繁延迟。用户反馈中的缺陷率居高不下,团队在…

张小明 2026/1/7 8:26:38 网站建设

建设银行jo 办网站用卡网站备案需要钱吗

声明 本文章中所有内容仅供学习交流使用,不用于其他任何目的,抓包内容、敏感网址、数据接口等均已做脱敏处理,严禁用于商业用途和非法用途,否则由此产生的一切后果均与作者无关! 逆向分析 部分python代码 data {&qu…

张小明 2026/1/6 18:24:55 网站建设