我对 ArrayList contains 方法的工作原理有疑问。举个例子:
List<String> lstStr = new ArrayList<String>();
String tempStr1 = new String("1");
String tempStr2 = new String("1");
lstStr.add(tempStr1);
if (lst.contains(tempStr2))
System.out.println("contains");
else
System.out.println("not contains");
它返回“不包含”。
另一个例子:
List<LinkProfileGeo> lst = new ArrayList<LinkProfileGeo>();
LinkProfileGeo temp1 = new LinkProfileGeo();
temp1.setGeoCode("1");
LinkProfileGeo temp2 = new LinkProfileGeo();
temp2.setGeoCode("1");
lst.add(temp1);
if (lst.contains(temp2))
System.out.println("contains");
else
System.out.println("not contains");
它返回包含。那么 contains 方法是如何工作的呢?
谢谢