在JAVA语言中,字符串数据实际上由String类所实现的。Java字符串类分为两类:一类是在程序中不会被改变长度的不变字符串;二类是在程序中会被改变长度的可变字符串。Java环境为了存储和维护这两类字符串提供了 String和StringBuffer两个类。 一、创建字符串 例: String str=new("This is a String");
或者 String str="This is a String";
二、得到字符串对象的有关信息 1.通过调用length()方法得到String的长度. 例:
String str="This is a String"; int len =str.length();
String str="This is a String"; Int index1 =str.indexOf("i"); //index=2 Int index2=str.indexOf('i',index+1); //index2=5 Int index3=str.lastIndexOf("I"); //index3=15 Int index4=str.indexOf("String"); //index4=10