String常用方法
public class first {public static void main(String args[]){ String asd = "helloworld"; String asf = "hello world love"; System.out.println(asd.contains("hello"));//判断“hello”是否存在 System.out.println(asd.indexOf("d",5));//从第5开始查找 d 的位置 返回他的索引找不到返回-1 System.out.println(asd.lastIndexOf("h",1)); System.out.println(asd.startsWith("ll",1));//从索引1开始查找 判断是否以ll开头 System.out.println(asd.replaceAll("o","-"));//把o替换成- System.out.println(asd.substring(1,5)); String it [] = asf.split("\\ ");//拆分操作 for (int x=0;x<it.length ;x++ ) { System.out.println(it[x]); } } }