- 博客(4)
- 收藏
- 关注
原创 自学java之比较器排序
注意: 1.使用TreeSet集合存储对象,带参构造方法利用比较器对元素排序 2.在TreeSet集合的构造方法接受Comparator的实现类对象,重写compare方法 测试样例 public static void main(String[] args) { TreeSet<Student> t= new TreeSet<Student>(new Comparator<Student>(){ @Override
2020-05-17 22:04:43 112
原创 自学Java笔记之自然排序Comparable
注意: 1.TreeSet集合存储自定义对象,调用无参构造方法时,是对元素的自然排序 2.必须在元素所属类中重写comparTo方法,其返回值决定自然排序的是升序还是降序,当返回值为1时降序,为-1时升序 3.若不实现comparable接口,则无法实现自然排序,会抛出异常 测试样例 public static void main(String[] args) { //创建集合对象 TreeSet<Student> t= new TreeSet<Stude
2020-05-17 21:35:13 164
原创 自学Java笔记之TreeSet集合
特点: 1.该集合内元素有序,指按一定的规则进行排序,排序方式由构造方法决定; 无参:依据元素的自然顺序进行排序 有参:依据指定的比较器进行排序 2.没有索引方法,无法使用普通for遍历 3.不包含重复元素 测试样例 public static void main(String[] args) { TreeSet<Integer> ts= new TreeSet<Integer> (); ts.add(2); ts.add(66);
2020-05-17 17:08:36 106
原创 自学Java笔记之LinkedHashSet集合
特点:1.哈希表和链表实现Set接口,具有能够预测的迭代次序 2.其中链表保证元素有序,使元素的存储和取出的次序是一样的 3.hash表保证元素唯一,没有重复元素 测试样例 public class LinkedHashSet集合 { public static void main(String[] args) { LinkedHashSet<String> linkedHashSet = new LinkedHashSet<String>();
2020-05-17 16:35:27 120
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人