欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

java String类的操作 博客分类: 代码 java string 

程序员文章站 2024-03-02 11:13:04
...

  System.out.println("abc".charAt(1));//返回指定索引处的 char 值。
System.out.println("abcd".compareTo("abcde"));//按字典须序比较 =0 >1 <-1
System.out.println("abc".compareToIgnoreCase("ABC"));//按字典顺序比较两个字符串,不考虑大小写。
System.out.println("abc".concat("def"));//将指定字符串连接到此字符串的结尾。
System.out.println("abc".contains("a"));//当且仅当此字符串包含指定的 char 值序列时,返回 true。
System.out.println("abc".endsWith("bc"));//  测试此字符串是否以指定的后缀结束。
System.out.println("abc".equalsIgnoreCase("ABC"));//将此 String 与另一个 String 比较,不考虑大小写。
System.out.println(String.format("我是一名%s%s", "程序员",100));// 使用指定的格式字符串和参数返回一个格式化字符串。
System.out.println("abc".hashCode());//返回此字符串的哈希码。
System.out.println("abc".indexOf('a'));// 返回指定字符在此字符串中第一次出现处的索引。
System.out.println("abcabc".indexOf('a', 1));//返回指定子字符串在此字符串中第一次出现处的索引,从指定的索引开始。
System.out.println("a b c".intern());//返回字符串对象的规范化表示形式。
System.out.println(" ".isEmpty());//当且仅当 length() 为 0 时返回 true。
System.out.println("abcabc".lastIndexOf('a'));//返回指定字符在此字符串中最后一次出现处的索引。
System.out.println("fdsf".matches("^\\d+$"));//告知此字符串是否匹配给定的正则表达式。
System.out.println("a  b c".replace(" ", ""));//返回一个新的字符串,它是通过用 newChar 替换此字符串中出现的所有 oldChar 得到的。
System.out.println("116abc".replaceAll("[0-9]", "*"));//使用给定的 replacement 替换此字符串所有匹配给定的正则表达式的子字符串。
System.out.println("aaaa".replaceFirst("[a-z]", "*"));//使用给定的 replacement 替换此字符串匹配给定的正则表达式的第一个子字符串。
System.out.println("a a [color=red][/color][align=center][/align]a".split(" ").length);//根据匹配给定的正则表达式来拆分此字符串。
System.out.println("abcd".startsWith("a"));//测试此字符串是否以指定的前缀开始。
char [] chars ="abcdefg".toCharArray();//将此字符串转换为一个新的字符数组。
for (int i = 0; i < chars.length; i++) {
System.out.print(chars[i]+" ");
}
System.out.println("ABCDEF".toLowerCase());//将此 String 中的所有字符都转换为小写。
System.out.println("abc".toUpperCase());//将此 String 中的所有字符都转换为大写。
System.out.println(String.valueOf(chars));// 返回 char 数组参数的字符串表示形式。
System.out.println(String.valueOf(true));//返回 boolean 参数的字符串表示形式。
System.out.println("abc".substring(1));//截取从1之后的字符串
System.out.println("abcdef".substring(0,2));//截取从0到2的字符串
相关标签: java string