码迷,mamicode.com
首页 > 其他好文 > 详细

String的方法运用

时间:2016-08-21 21:10:42      阅读:111      评论:0      收藏:0      [点我收藏+]

标签:

public class StringUse {
public static void main(String[] args) {
int count = 0;
String s=new String("hello!");
String b="hello";
String c="abcde";
String a=new String();
a="HELLO!";

//StringBUffer的charAt
StringBuffer sb=new StringBuffer("aibicimimi");
for(int i=0;i<sb.length();i++){
if(sb.charAt(i)==‘i‘){
count++;
}else{
continue;
}
}
System.out.println(count);

//delete
System.out.println(sb.delete(0, 2).toString());

//inser
System.out.println(sb.insert(2, "xixi"));

//charAt
/*System.out.println(s.charAt(4));

//codePointAt
System.out.println(s.codePointAt(4));

//codePointBefore
System.out.println(s.codePointBefore(4));

//codePointCount
System.out.println(s.codePointCount(2, 5));*/

//compareTo
/*System.out.println(s.compareTo(c));

//compareToIgnoreCase
System.out.println(s.compareToIgnoreCase(a));

//concat
System.out.println(s.concat(a));

//替代上面
String string="s:"+s+"a:"+a;
System.out.println(string);

//copyValueOf
char d[]=new char[]{‘h‘,‘m‘,‘n‘};
System.out.println(s.copyValueOf(d));
System.out.println(s);

//s.endsWith
System.out.println(s.endsWith("l"));

System.out.println(s.equalsIgnoreCase(a));

//getBytes
byte[] e=s.getBytes();
System.out.println(Arrays.toString(e));

//indexOf
System.out.println(s.indexOf("l"));*/

//lastIndexOf
/* System.out.println(s.lastIndexOf("l"));

//replace
System.out.println(s.replace(‘l‘, ‘o‘));

//split
String string[]=s.split("h");

System.out.println(Arrays.toString(string));*/

//substring
/*System.out.println(s.substring(1));

//toUpperCase
System.out.println(s.toUpperCase());
System.out.println(s.valueOf(2));*/

String的方法运用

标签:

原文地址:http://www.cnblogs.com/lili-num-01/p/5793545.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!