LinkedHashSet类

发布时间:2016-12-6 13:56:40 编辑:www.fx114.net 分享查询网我要评论
本篇文章主要介绍了"LinkedHashSet类",主要涉及到LinkedHashSet类方面的内容,对于LinkedHashSet类感兴趣的同学可以参考一下。

package ch3; public class Student { private int age; private String name; Student(int num,String name) { this.age =num; this.name =name; } @Override public boolean equals(Object o) { // TODO Auto-generated method stub Student s =(Student)o; return age ==s.age&&name.equals(s.name); } @Override public int hashCode() { // TODO Auto-generated method stub return age*name.hashCode(); } @Override public String toString() { // TODO Auto-generated method stub return "age:" +age+"name:"+name; } } package ch3; import java.util.Iterator; import java.util.LinkedHashSet; import java.util.Set; public class LinkedHashSetText { public static void main(String[] args) { Set<Student> linkHashSet = new LinkedHashSet<Student>(); Student s1 = new Student(18,"zhj"); Student s2 = new Student(25,"zyj"); Student s3 = new Student(28,"xml"); Student s4 = new Student(18,"zah"); Student s5 = new Student(18,"zah");//有序,不能重复 linkHashSet.add(s1); linkHashSet.add(s2); linkHashSet.add(s3); linkHashSet.add(s4); linkHashSet.add(s5); linkHashSet.add(null); Iterator in = linkHashSet.iterator(); while(in.hasNext()) { System.out.println(in.next()); } } }

上一篇:chromium 书签实现机制
下一篇:安卓刷机及刷机包制作教程

相关文章

关键词: LinkedHashSet类

相关评论