首页 > 其他 > 详细

String

时间:2018-05-02 01:52:32      阅读:194      评论:0      收藏:0      [点我收藏+]

String s1 = new String("abc");

String s2 = new String("abc");

System.out.println(s1 == s2);  /* 结果返回false */

System.out.println(s1.equals(s2));  /* 结果返回true */

String s3 = "abc";

String s4 = "abc";

System.out.println(s3 == s4);  /* 此时结果返回true */

System.out.println(s4.isEmpty());  /* 判断字符串是否为空 */

System.out.println(s4.charAt(2));  /* 返回指定下标2的字符c */

System.out.println(s4.indexOf(‘a‘));  /* 返回对应字符的下标,若存在多个相同字符,则返回第一个的下标值。若不存在指定的字符,则返回-1 */

System.out.println(s4.substring(1));  /* 从指定下标1开始截取字符串直到最后,返回新的字符串("bc") */

System.out.println(s4.replace(‘a‘, ‘*‘));  /* 将字符串的‘a‘字符串全部用新字符‘*‘取代,返回一个新的字符串 */

String s5 = "abc,de,fghi";
String[] s = s5.split(",");  /* 将字符串以","为分界进行切割,返回一个字符串数组 */
for (int i = 0; i < s.length; i++) {
  System.out.println(s[i]);
}

String s6 = " aa bb ";

System.out.println(s6.trim());  /* 去除字符串的首尾空格,中间的空格不去除,返回一个新的字符串 */

String

原文:https://www.cnblogs.com/ss-123/p/8978169.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!