public static void main(String[] args) {
Collection c1 = new ArrayList();
c1.add(new String("abc"));
String s = new String("abc");
//字符串重写了equals方法,比较的是内容所以相等
System.out.println(c1.contains(s));//true
/**
* public int indexOf(Object o) {
* if (o == null) {
* for (int i = 0; i < size; i++)
* if (elementData[i]==null)
* return i;
* } else {
* for (int i = 0; i < size; i++)
* if (o.equals(elementData[i]))
* return i;
* }
* return -1;
* }
*/
}
}
7.集合的包含方法
最新推荐文章于 2022-10-11 09:18:29 发布