正式开始学习JAVA,开个贴子记录下学习过程中的点点滴滴把。PHP还没精通就开始学JAVA,专业课没办法,既然学了,就学好吧。但语言总是想通的,学习JAVA过程中反而看到了好多jQuery的影子。
字符串,不同于C语言中的字符串,JAVA中的字符串是一种特殊的类。拥有很多的方法。例如:
1.可以将字符类型数组转换成字符串形式:
char i[]={'a','b','c','d'};
String m=new String(i);
System.out.println(m);//结果是"abcd"
2.可以将固定长度的字符型数组转换成字符串形式:
char i[]={'a','b','c','d'};
String m=new String(i,1,2);//1代表其实位置,2代表长度。2可以缺省
System.out.println(m);
3.可以将byte型的数字转成字符串形式:
byte i[]={98,99,100,101,102,103};
String m=new String(i);
System.out.println(m);
4.可以将固定长度的byte型的数字转成字符串形式:
byte i[]={98,99,100,101,102,103};
String m=new String(i,2,1);
System.out.println(m);
5.返回特定位置的出的字符:
String i="hellow world";
char m=i.charAt(2);
System.out.println(m);
6.截取特定位置的一定长度的字符串:
String i="hellow world";
String m=i.substring(2,7);
System.out.println(m);
7. 返回第一次出现的指定子字符串在此字符串中的索引:
String i="hellow world";
int m=i.indexOf('e');
System.out.println(m);
还有很多很多的字符串的方法,就不一一列举了,还是参考手册不=吧。