indexOf()方法:返回待匹配串的出現的第一個位置;如果不匹配,返回-1
String str1="XABCYZ"; String str2="ABC"; System.out.println(str1.indexOf(str2));//1 System.out.println(str1.indexOf(1));//-1
contains()方法:內部調用indexOf()
public boolean contains(CharSequence s) { return indexOf(s.toString()) > -1; }