å¯ä»¥ç¨Stringç±»çindexOfå½æ°ï¼
æ¯å¦ï¼
æ¥è¯¢âasdasdasxxxxqweâä¸æ¯å¦å
å«âasdasâï¼
å¯ä»¥ç¨ "asdasdasxxxxqwe".indexOf("asdas")
å½å
å«æ¶è¿å大äºçäº0ï¼å¦åè¿åå°äº0ï¼ä¸è¬æ¯-1ï¼
è¿ä¸ªé®é¢ï¼é¦å
è¦å°stringæ°ç»è½¬æ¢ælistéåï¼ç¶åå¤ælistéåä¸æ¯å¦åå¨
public static void main(String[] args) {
//å®ä¹æ°ç»
String aa []={"timo","kainan","naer","lanbo"};
//æ°ç»è½¬æ¢ælist
List<String> list=Arrays.asList(aa);
if(list.contains("timo")){
System.out.println("ææè«");
}else{
System.out.println("没ææè«");
}
}
温馨提示:内容为网友见解,仅供参考