zoukankan      html  css  js  c++  java
  • 反射认识_06_ArrayList_HashSet区别

    包01:

    package ReflectionCollection;
    
    public class ReflectionConstructorPoint {
    	private int x;
    	public int y;
    	
    	public ReflectionConstructorPoint(int x, int y) {
    		super();
    		this.x = x;
    		this.y = y;
    	}
    }
    

      

    包02:

    package ReflectionCollection;
    
    import java.util.ArrayList;
    import java.util.Collection;
    import java.util.HashSet;
    
    public class ReflectionConstructor {
    	public static void main(String[] args) throws Exception {
    		ReflectionConstructorPoint rcp1=new ReflectionConstructorPoint(1, 1);
    		ReflectionConstructorPoint rcp2=new ReflectionConstructorPoint(2, 2);
    		ReflectionConstructorPoint rcp3=new ReflectionConstructorPoint(3, 3);
    
    		/*验证ArrayList,重复添加后大小,有序集合*/
    		Collection col1=new ArrayList();
    		col1.add(rcp1);
    		col1.add(rcp1);//第二次添加
    		col1.add(rcp2);
    		col1.add(rcp3);
    		System.out.println(col1.size());//结果为4
    
    		/*验证HashSet,重复添加后大小,无序集合*/
    		Collection col2=new HashSet();
    		col2.add(rcp1);
    		col2.add(rcp1);//第二次添加
    		col2.add(rcp2);
    		col2.add(rcp3);
    		System.out.println(col2.size());//结果为3
    	}
    }
    

      

  • 相关阅读:
    多态问题----针对方法
    画了个Android——Canvas类的使用(转)
    设计模式之策略模式
    Listview多种布局的使用
    Activity的退出和進入效果
    java.lang.ClassNotFoundException
    台球小游戏
    线性表
    堆栈
    动态内存管理
  • 原文地址:https://www.cnblogs.com/zjsy/p/4154031.html
Copyright © 2011-2022 走看看