我正在存储代表要跟踪的对象索引的整型对象。后来在我的代码中,我想检查特定对象的索引是否对应于我之前存储的那些整数之一。在ArrayList中比较新的整型对象问题
ArrayList<Integer> courseselectItems = new ArrayList();
//Find the course elements that are within a courseselect element and add their indicies to the ArrayList
for(int i=0; i<numberElementsInNodeList; i++) {
if (nodeList.item(i).getParentNode().getNodeName().equals("courseselect")) {
courseselectItems.add(new Integer(i));
}
}
那么我想以后检查ArrayList包含特定的索引::我通过创建一个ArrayList,并从一个索引创建一个新的整数for循环这样
//Cycle through the namedNodeMap array to find each of the course codes
for(int i=0; i<numberElementsInNodeList; i++) {
if(!courseselectItems.contains(new Integer(i))) {
//Do Stuff
}
}
我问题是,当我使用new Integer(i)
创建一个新的整数时,我可以使用ArrayList.contains()
来比较整数吗?也就是说,当我使用new Integer(i)
创建一个新对象时,如果用于创建它们的int值相同,它是否与以前创建的Integer对象相同?
我希望我没有把它弄得太模糊。谢谢您的帮助!
在旁注中,下面是一些值得了解整数和字符串的知识:http://www.devx.com/tips/Tip/42276 – 2010-04-14 01:30:04