@Test
public void demo(){ // 以下为String中的常用的方法及注释, 最常用的注释前有**标注
String s = "abcdefg123456"; // 返回下标对应的ASCII码
int codePointAt = s.codePointAt(7);
// **返回字符串s和字符串Q的,第一个不相等字符的ASCII码差值,如果查找结束发现都相等,则返回两个字符串的长度差值
int compareTo = s.compareTo("Q");
// 返回下标前一位对应的ASCII码
int codePointBefore = s.codePointBefore(7);
// 返回代码点长度
int codePointCount = s.codePointCount(4, 7);
// 返回从index=4处偏移到codePointOffSet=7之后的索引
int offsetByCodePoints = s.offsetByCodePoints(4, 7);
// 将字符串变成字节数组
byte[] getBytes = s.getBytes();
// **将字符串变成字符数组
char[] toCharArray = s.toCharArray();
// **返回指定索引出的字符
char charAt = s.charAt(7);
// **是否包含字符串"contains"
boolean contains = s.contains("contains");
// **将字符串s中的c全部替换为C
String replaceAll = s.replaceAll("c", "C");
// 将字符串中的1替换为一
String replace = s.replace("1", "一");
// **截取字符串s中的索引从0到3的字符
String substring = s.substring(0, 3);
// 截取字符串s中索引从4开始的字符
String substring1 = s.substring(4);
// 字符串s是否以6结尾
boolean endsWith = s.endsWith("6");
// 字符串是否以a开头
boolean startsWith = s.startsWith("compareTo");
// **将字符串s以字符c进行分割
String[] split = s.split("c");
// 将字符串s以字符c进行分割,分割成3份(如果最大能够分割到3份的话,如果最大不能分割到3份,则默认分割到最大份数)
String[] split1 = s.split("c", 3);
// 将字符串7890拼接到字符串s的后面,与+拼接字符串的区别是,+号左右的字符串都可以是null,而concat左右都不允许,否则会报空指针异常
String concat = s.concat("7890");
// 返回字符串是否相等,与equals区别,equals仅限于两个String类型字符串进行比较,而contentEquals可以比较类型为CharSequence的,
// 而且如果比较的是StringBuffer还会加锁
boolean contentEquals = s.contentEquals("contentEquals");
// 比较两个字符串是否相等(忽略大小写),
boolean equalsIgnoreCase = s.equalsIgnoreCase("Abcdefg123456");
// **比较两个字符串是否相等(不忽略大小写)
boolean equals = s.equals("contentEquals");
// 判断字符串是否为空
boolean empty = s.isEmpty();
// **获取字符串的长度
int length = s.length();
// **返回指定字符在字符串s中的索引,如果找不到返回-1
int indexOf = s.indexOf("一");
// 将字符串全部转换为小写
String toLowerCase = s.toLowerCase();
// 将字符串全部转换为大写
String toUpperCase = s.toUpperCase();
// 去除字符串前后的空格
String trim = " abc ".trim();
// 将指定数量的字符串(s,7890,AAA)以固定格式(,)进行拼接
String join = String.join(",",s, "7890", "AAA"); System.out.println("codePointAt = " + codePointAt);
System.out.println("compareTo = " + compareTo);
System.out.println("codePointBefore = " + codePointBefore);
System.out.println("codePointCount = " + codePointCount);
System.out.println("offsetByCodePoints = " + offsetByCodePoints);
System.out.println("getBytes = " + Arrays.toString(getBytes));
System.out.println("toCharArray = " + Arrays.toString(toCharArray));
System.out.println("charAt = " + charAt);
System.out.println("contains = " + contains);
System.out.println("replaceAll = " + replaceAll);
System.out.println("replace = " + replace);
System.out.println("substring = " + substring);
System.out.println("substring1 = " + substring1);
System.out.println("endsWith = " + endsWith);
System.out.println("startsWith = " + startsWith);
System.out.println("split = " + Arrays.toString(split));
System.out.println("split1 = " + Arrays.toString(split1));
System.out.println("concat = " + concat);
System.out.println("contentEquals = " + contentEquals);
System.out.println("equalsIgnoreCase = " + equalsIgnoreCase);
System.out.println("indexOf = " + indexOf);
System.out.println("toLowerCase = " + toLowerCase);
System.out.println("toUpperCase = " + toUpperCase);
System.out.println("join = " + join);
System.out.println("equals = " + equals);
System.out.println("empty = " + empty);
System.out.println("length = " + length);
System.out.println("trim = " + trim);
}
上述打印结果为: codePointAt = 49
compareTo = 16
codePointBefore = 103
codePointCount = 3
offsetByCodePoints = 11
getBytes = [97, 98, 99, 100, 101, 102, 103, 49, 50, 51, 52, 53, 54]
toCharArray = [a, b, c, d, e, f, g, 1, 2, 3, 4, 5, 6]
charAt = 1
contains = false
replaceAll = abCdefg123456
replace = abcdefg一23456
substring = abc
substring1 = efg123456
endsWith = true
startsWith = false
split = [ab, defg123456]
split1 = [ab, defg123456]
concat = abcdefg1234567890
contentEquals = false
equalsIgnoreCase = true
indexOf = -1
toLowerCase = abcdefg123456
toUpperCase = ABCDEFG123456
join = abcdefg123456,7890,AAA
equals = false
empty = false
length = 13
trim = abc
以上为个人总结记录使用,希望能够帮助其他人,如有不足或错误欢迎大家指正。

最新文章

  1. Percona Toolkit 使用
  2. 无线安全审计工具 Fern WiFi Cracker
  3. Spring入门_03_构造注入
  4. CLR via C#(09)-扩展方法
  5. 使用git提交本地代码到github
  6. Swift实战-豆瓣电台(九)简单手势控制暂停播放(全文完)
  7. POJ 3162 Walking Race 树形DP+线段树
  8. 同时使用Binding&StringFormat 显示Text【项目】
  9. 【linux c learn 之stat】获取文件的属性
  10. matlab高斯模板生成,K是归一化系数,上面是一个半径200的高斯模板用来做MSR
  11. android:baselineAligned属性
  12. ZOJ 3604 Tunnel Network(凯莱定理)
  13. tomcat8 源码分析 | 组件及启动过程
  14. UITableView自定义Cell中,纯代码编程动态获取高度
  15. CF369E Valera and Queries
  16. Windows环境下在IDEA编辑器中spark开发安装步骤
  17. ftp服务器搭建流程详解
  18. 二、认识Xcode(第一个工程:Hello world)
  19. 安卓开发_浅谈AsyncTask
  20. M2阶段团队贡献分

热门文章

  1. Linux wget 批量下载
  2. 学习笔记15_ASP母版页
  3. 用js给元素增加链接
  4. Linux命令实战(四)
  5. CentOS7 reset脚本,用于初始化新的虚拟机
  6. 实验:基于http的yum源
  7. MySQL添加主键和外键
  8. java中继承,子类是否继承父类的构造函数
  9. 全网阅读过20k的Java集合框架常见面试题总结!
  10. abp(net core)+easyui+efcore实现仓储管理系统——ABP WebAPI与EasyUI结合增删改查之一(二十七)