1.2String类型基本方法与属性
public class Test
{
public static void main(String[] args)
{
String s="000111222333";
StdOut.printf("s is:%s
",s);
//
StdOut.printf("s length=%d
",s.length());
//
for(int i=0;i<s.length();i++)
StdOut.printf("postion is %d,char is:%s
",i,s.charAt(i));
//
for(int i=0;i<s.length();i++)
StdOut.printf("char %s first postion is %d
",s.charAt(i),s.indexOf(s.charAt(i)));
//
for(int i=0;i<s.length();i++)
StdOut.printf("char %s 1st and 2nd postion is %d
%d
",s.charAt(i),s.indexOf(s.charAt(i)),s.indexOf(s.charAt(i),s.indexOf(s.charAt(i))+1));
//
String s2="";
for(int i=0;i<s.length();i=i+3)
{
s2=s2.concat(s.substring(i,i+1)+ " ");
StdOut.printf("s2 concat partion of s is:%s
",s2);
}
//
String[] words=s2.split(" ");
for(int i=0;i<words.length;i++)
StdOut.printf("words i %d is %s
",i,words[i]);
//
StdOut.printf("s2 compare s2 is %s,s2 compare s is %s
",s2.compareTo(s2),s2.compareTo(s));
//
StdOut.printf("s2 equals s2 is %s,s2 equals s is %s
",s2.equals(s2),s2.equals(s));
}
}