import java.util.ArrayList;
import java.util.Iterator; public class ArrayListTest {
public static void main(String[] args) {
ArrayList<Person> list = new ArrayList<Person>();
list.add(new Person("wangcai", 21));
list.add(new Person("zhangsan", 22));
list.add(new Person("lisi", 23));
list.add(new Person("zhaoliu", 24));
list.add(new Person("wangcai", 21));
list.add(new Person("lisi", 23));
System.out.println(list);
list=getNewList(list);
System.out.println(list);
singleStringDemo();
} public static void singleStringDemo(){
ArrayList list=new ArrayList();
list.add("java01");
list.add("java02");
list.add("java05");
list.add("java02");
list.add("java04");
list.add("java05");
list.add("java04");
System.out.println(list);
list=getNewList(list);
System.out.println(list);
} public static ArrayList getNewList(ArrayList list) {
ArrayList temp = new ArrayList();
Iterator it = list.iterator();
while(it.hasNext()) {
Object obj = it.next();
if (!temp.contains(obj)) {
temp.add(obj);
}
}
return temp;
}
}
 public class Person {
private String name;
private int age; public Person() {
super();
} public Person(String name, int age) {
super();
this.name = name;
this.age = age;
} public String getName() {
return name;
} public void setName(String name) {
this.name = name;
} public int getAge() {
return age;
} public void setAge(int age) {
this.age = age;
} @Override
public String toString() {
return "Person [name=" + name + ", age=" + age + "]";
} }

集合,ArrayList练习的更多相关文章

  1. Java ArrayList和Vector、LinkedList与ArrayList、数组(Array)和列表集合(ArrayList)的区别

    ArrayList和Vector的区别ArrayList与Vector主要从二方面来说.  一.同步性:   Vector是线程安全的,也就是说是同步的,而ArrayList是线程序不安全的,不是同步 ...

  2. 集合ArrayList

    /*集合ArrayList * 例如: * 1.创建:ArrayList<Egg> myList = new ArrayList<Egg>(); *      Egg类型的集合 ...

  3. 面向对象之集合ArrayList

    using System; using System.Collections; using System.Collections.Generic; using System.Linq; using S ...

  4. 集合及特殊集合arrayList

    1,运用集合  arrayList 首先复制Colections加  : 创建arrayList ar =new arrayList(); ArrayList具体提供的功能:属性            ...

  5. Java 集合 ArrayList和LinkedList的几种循环遍历方式及性能对比分析 [ 转载 ]

    Java 集合 ArrayList和LinkedList的几种循环遍历方式及性能对比分析 @author Trinea 原文链接:http://www.trinea.cn/android/arrayl ...

  6. 数组Array和列表集合ArrayList、LinkedList和Vector的区别

    一.ArrayList和Vector的区别 ArrayList与Vector主要从以下方面来说. 1.同步性: Vector是线程安全的,也就是说是同步的,而ArrayList是线程序不安全的,不是同 ...

  7. 第三章泛型集合ArrayList 和Hashtable

    第三章泛型集集合 ArrayList 变量名 = new ArrayList();  //相当与一个容器 他的执行using 是  using System.Collections; 变量名.ADD( ...

  8. JAVA基础——集合——ArrayList

    ArrayList集合 ArrayList的一些方法(JDK1.8): 将指定的元素附加到列表的末尾,true:添加成功,false:添加失败: public boolean add(E e)    ...

  9. 反射方式,获取出集合ArrayList类的class文件对象

    /* * 定义集合类,泛型String * 要求向集合中添加Integer类型 * * 反射方式,获取出集合ArrayList类的class文件对象 * 通过class文件对象,调用add方法 * * ...

  10. Java中list集合ArrayList 中contains包含的使用

    Java中list集合ArrayList 中contains包含的使用 https://blog.csdn.net/qq_38556611/article/details/78774690

随机推荐

  1. 微信小程序scroll-view隐藏滚动条方法

    在wxss里加入以下代码: ::-webkit-scrollbar{ width: 0; height: 0; color: transparent; }   源链接:https://blog.csd ...

  2. java面试题之----jdbc中使用的设计模式(桥接模式)

    1.JDBC(JavaDatabase Connectivity) JDBC是以统一方式访问数据库的API. 它提供了独立于平台的数据库访问,也就是说,有了JDBC API,我们就不必为访问Oracl ...

  3. Hadoop Federation联邦

    背景概述 单 NameNode 的架构使得 HDFS 在集群扩展性和性能上都有潜在的问题,当集群大到一定程度后,NameNode 进程使用的内存可能会达到上百 G,NameNode 成为了性能的瓶颈. ...

  4. SQL Server ->> 斐波那契数列(Fibonacci sequence)

    斐波那契数列(Fibonacci sequence)的T-SQL实现 ;WITH T AS ( AS BIGINT) AS curr, CAST(NULL AS BIGINT) AS prv UNIO ...

  5. jdbc 块提取方式

    最近使用jdbc方式查询数据,保存为csv文件中.当然你可以在pl/sql中直接查出来,copy to excel就好了.但我想通过程序实现 1 @Test 2 public void test() ...

  6. JavaScript检测数据类型

    JavaScript检测数据类型 标签(空格分隔): JavaScript function valType(value) { return Object.prototype.toString.cal ...

  7. July 04th 2017 Week 27th Tuesday

    Nothing is really beautiful but truth. 只有真理才是真美. Truth can be beautiful, but it also can be cruel. W ...

  8. January 20 2017 Week 3 Friday

    I am a slow walker, but I never walk backwards. 我走得很慢,但我从来不会后退. In the past years, I walked very slo ...

  9. February 16 2017 Week 7 Thursday

    Other men live to eat, while I eat to live. 很多人为食而生存,而我为生存而食. Just the same, either you eat to live ...

  10. Python 冒泡排序法分析

    冒泡排序法 def maopao(): array = [2,1,3,6,5,4] #确定一组需要排序的数值列表 for i in range(len(array)-1): #大循环次数=列表长度,但 ...