• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
第二天半
博客园    首页    新随笔    联系   管理    订阅  订阅

反射认识_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
	}
}

  

posted @ 2014-12-09 20:04  第二天半  阅读(193)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3