Design and implement a data structure for Least Frequently Used (LFU) cache. It should support the following operations: get and set. get(key) - Get the value (will always be positive) of the key if the key exists in the cache, otherwise return -1. s
TreeSet是实现Set接口的实现类.所以它存储的值是唯一的,同时也可以对存储的值进行排序,排序用的是二叉树原理.所以要理解这个类,必须先简单理解一下什么是二叉树. 二叉树原理简析 假如有这么一个集合TreeSet<Integer>是[5,11,6,5,23,14] 用二叉树是怎么排序的呢? 二叉树遍历方法比较多,有兴趣自己百度看下吧.这里只需要知道元素是怎么插入到二叉树即可.小的存储在左边(负数),大的存储在右边(正数),相等不存储. TreeSet的基本使用 @Test public v
17.01 ArrayList集合的toString()方法源码解析 代码: Collection c = new ArrayList(); c.add("hello"); c.add("world"); c.add("java"); System.out.println(c); 输出c时默认调用的是c的toString()方法 A:Collection c = new ArrayList(); 这是多态,所以输出c的 toStri
1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结集合与泛型相关内容. 1.2 选做:收集你认为有用的代码片段 答:主要以泛型为主 //简单的泛型类的定义,T为类型参数 public class Pair<T> { public Pair(T first, T second) { this.first = first; this.second = second; } public T getFirst() { return first; } public void setFi
1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结集合与泛型相关内容. 1.2 选做:收集你认为有用的代码片段 简单泛型定义: public class Pair<T> { public Pair(T first, T second) { this.first = first; this.second = second; } public T getFirst() { return first; } public void setFirst(T newValue) { fir