public boolean equals(Object obj):比较字符串的内容是否相同
System.out.println(s.equals("abcd"));
System.out.println(s.equalsIgnoreCase("abcd"));
public int Length():获取字符串的长度,其实也就是字符个数
System.out.println(s.length());
public boolean contains(String s):判断是否包含传入的字符串,包含true,不包包含返回false
System.out.println(s.contains("ac"));
public String substring(int start):从start开始截取字符串 // 方法的返回值值截取后的字符串
System.out.println(s.substring(1));
public String substring(int start,int end):从start开始,到end结束截取字符串。包括start,不包括end ,如果end传入的是字符串最大索引+1的话则不会报出索引越界异常
System.out.println(s.substring(日, 3));
public String toLowerCase():把字符串转换为小写字符串
System.out.println(s.toLowerCase());
public String toUpperCase():把字符串转换为大写字符串
System.out.println(s.toUpperCase());
public String[] split(String str):根据传入的字符串切割屬字符中,返回的是字符串数组注意:如果切割的是.或者其他符号的话需要加上转义字符:s.split("\\.");
String s = "ab cb cd";
String[] strs = s.split(" ");
System.out.println(Arrays.toString(strs));
String s=new String("abc"),创建 StringObject分为两种情况:
String 它被用于裁剪,拼接。搜索字符串,比较字符串,截取字符串,转换大 小写等。在项目中不经常发生变化的业务场景中,优先使用 String。
本文由 Alicyu 创作,如果您觉得本文不错,请随意赞赏
采用 知识共享署名4.0 国际许可协议进行许可
本站文章除注明转载/出处外,均为本站原创或翻译,转载前请务必署名
原文链接:https://www.alicyu.com/archives/String
最后更新:2019-10-18 15:18:11
Update your browser to view this website correctly. Update my browser now