当前位置:网站首页>String common methods
String common methods
2022-08-10 05:50:00 【hagong9】

package com.zhang.String.Demo01;import java.util.Arrays;public class Demo02 {public static void main(String[] args) {String str = "java is the best language in the world, javan is awesome";//length(); returns the length of the stringSystem.out.println(str.length());//charAt(int index) returns the character at a certain positionSystem.out.println(str.charAt(str.length()-2));//Get the last one (counting from the back to the front, the first - a few)//contains (String str); determine if a string is containedSystem.out.println(str.contains("edfsd"));System.out.println(str.contains("world"));System.out.println("==============================================================");//toCharArray() returns the array corresponding to the stringSystem.out.println(Arrays.toString(str.toCharArray()));//indexOf() returns the position of the first occurrence of the stringSystem.out.println(str.indexOf("java"));System.out.println(str.indexOf("java",4));//Look back from the fifth corner mark//lastIndexOf() returns the position of the last occurrence of the stringSystem.out.println(str.lastIndexOf("java"));System.out.println("======================================================");String str2 = "Hello World";//trim() removes the spaces before and after the stringSystem.out.println(str2.trim());//toUpperCase() convert lowercase to uppercase toLowerCase convert uppercase to lowercaseSystem.out.println(str2.toUpperCase());System.out.println(str2.toLowerCase());//endWith(str) determines whether it ends with XX starWith (str) determines whether it starts with xxString str3 = "hello java";System.out.println(str3.endsWith("java"));System.out.println(str3.startsWith("hello"));System.out.println("================================================");//replace(char old, char new) replace the old character with the new characterSystem.out.println(str.replace("java","php"));//split() classifies stringsString say = "java is the best programming language,java";String[] arr = say.split("[ ,]+");//Use space sum, split + means space sum, there can be multiplefor (String string : arr){System.out.println(string);}//equalsString s1 = "hello";String s2 = "HELLO";System.out.println(s1.equalsIgnoreCase(s2));//Ignore case}}
Variable String
StringBuffer; variable-length string, slow and thread-safe.
StingBuilder; variable-length strings, fast, thread-unsafe
package com.zhang.baozhuang.Demo01;public class Demo03 {public static void main(String[] args) {StringBuffer sb = new StringBuffer();//append(); appendsb.append("java world first");System.out.println(sb.toString());sb.append("java is really fragrant");System.out.println(sb.toString());sb.append("java awesome");System.out.println(sb.toString());//insert() addsb.insert(0,"I am at the front");System.out.println(sb.toString());// replace() replacesb.replace(0,4,"hello");//Including the head but not the tail//de;ete() deletesb.delete(0,5);System.out.println(sb.toString());// clearsb.delete(0,sb.length());System.out.println(sb.toString());}}StringBuider is used in the same way as above.
边栏推荐
- error in ./node_modules/cesium/Source/ThirdParty/zip.js
- redis---非关系型数据库(NoSql)
- cesium add point, move point
- tinymce富文本编辑器
- network security firewall
- 并查集原理与API设计
- The submenu of the el-cascader cascade selector is double-clicked to display the selected content
- I use this recruit let the team to improve the development efficiency of 100%!
- Linux数据库Oracle客户端安装,用于shell脚本用sqlplus连接数据库
- Multi-table query Notes
猜你喜欢

链读好文:热加密存储与冷加密存储有什么区别?

Chain Reading|The latest and most complete digital collection sales calendar-08.02

PCL,VS配置过程中出现:用 _sopen_s 代替 _open, 或用_CRT_SECURE_NO_WARNNINGS错误

国内数字藏品投资价值分析

Count down the six weapons of the domestic interface collaboration platform!

事务、存储引擎

21天挑战杯MySQL——Day06

文章复现:超分辨率网络FSRCNN

网安超基础一周目

Chain Reading | The latest and most complete digital collection calendar-07.28
随机推荐
Chain Reading|The latest and most complete digital collection sales calendar-08.02
利用 crontab 拷贝大文件
sqlplus 显示上一条命令及可用退格键
el-dropdown drop-down menu style modification, remove the small triangle
深度学习中数据到底要不要归一化?实测数据来说明!
常用类 String概述
链读|最新最全的数字藏品发售日历-08.02
error in ./node_modules/cesium/Source/ThirdParty/zip.js
AWR1843型号毫米波雷达使用
cesium rotate image
视图【】【】【】【】
wiki confluence installation
集合 Map
Chain Reading Recommendation: From Tiles to Generative NFTs
网络安全7
操作表 函数的使用
kaggle小白必看:小白常见的2个错误解决方案
Linux database Oracle client installation, used for shell scripts to connect to the database with sqlplus
shell脚本中利用sqlplus操作数据库
Models corresponding to each architecture instruction set