arrayList的合并:
package listTest;//arrayList的合并
import java.util.ArrayList;
public class arrayListTest {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
addList();
}
private static void addList()
{
int i=0;
ArrayList<Number> list1=new ArrayList<Number>();
ArrayList<Number> list2=new ArrayList<Number>();
list1.add(1);
list2.add(2);
list1.addAll(list2);
for (Number number : list1) {
System.out.println("第"+i+"个数为:"+number+"
");
}
}
}
删除arrayList中重复元素:
HashSet<Number> hslist= new HashSet<Number>(list);
list.clear();
list.addAll(hslist);
或者
for (int i = 0; i < list.size() - 1; i++) {
for (int n = list.size() - 1; n > i; n--) {
if (list.get(n).equals(list.get(i))) {
list.remove(n);
}
}
}