会员
周边
众包
新闻
博问
闪存
赞助商
Chat2DB
所有博客
当前博客
我的博客
我的园子
账号设置
简洁模式
...
退出登录
注册
登录
spring学习笔记
java例程练习(容器类简单练习)
import java.util.ArrayList; import java.util.Collection; public class Test { public static void main(String[] args) { Collection<Object> c = new ArrayList<Object>(); c.add("hello"); c.add(new Name("f1", "l1")); c.add(new Integer(100)); System.out.println(c.size()); System.out.println(c); } } class Name { private String firstName; private String lastName; Name(String firstName, String lastName) { this.setFirstName(firstName); this.setLastName(lastName); } public void setFirstName(String firstName) { this.firstName = firstName; } public String getFirstName() { return firstName; } public void setLastName(String lastName) { this.lastName = lastName; } public String getLastName() { return lastName; } public String toString() { return firstName + " " + lastName; } }
//精彩继续
<pre name="code" class="java">import java.util.ArrayList; import java.util.Collection; public class Test { public static void main(String[] args) { Collection<Object> c = new ArrayList<Object>(); c.add("hello"); c.add(new Name("f1", "l1")); c.add(new Integer(100)); System.out.println(c.size()); System.out.println(c); System.out.println(); c.remove("hello"); c.remove(new Integer(100)); System.out.println(c.remove(new Name("f1", "l1"))); System.out.println(c); } } class Name { private String firstName; private String lastName; Name(String firstName, String lastName) { this.setFirstName(firstName); this.setLastName(lastName); } public void setFirstName(String firstName) { this.firstName = firstName; } public String getFirstName() { return firstName; } public void setLastName(String lastName) { this.lastName = lastName; } public String getLastName() { return lastName; } public String toString() { return firstName + " " + lastName; } public boolean equals(Object obj) { if(obj instanceof Name) { Name name = (Name) obj; return (firstName.equals(name.firstName)) && (lastName.equals(name.lastName)); } return super.equals(obj); } public int hashCode() { return firstName.hashCode(); } }
posted on
2012-04-30 20:29
spring学习笔记
阅读(
179
) 评论(
0
)
编辑
收藏
举报
刷新页面
返回顶部
导航
博客园
首页
联系
订阅
管理
公告