Set 到 Map的扩展--- 继承set
来源:互联网 发布:淘宝天天特价报名费用 编辑:程序博客网 时间:2024/05/15 23:54
public class Set2MapTest<K, V> extends HashSet<TestSimpleEntry<K,V>>{
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Set2MapTest<String,Integer> map = new Set2MapTest<String, Integer>();
map.put("测试", 100);
int a= map.put("map",50);
int b = map.put("数学", 88);
map.put("数学1", 88);
System.out.println(map.put("计算机", 818)+":位置");
System.out.println(map.get("map"));
System.out.println(map.containsValue(50)+",Map大小是:"+map.size());
Set2MapTest<String,Integer> map1 = new Set2MapTest<String, Integer>();
System.out.println(map1.hashCode());
List ary = new ArrayList(2);
ary.add(1);
ary.add(2);
ary.add(3);
System.out.println("List的长度:"+ary.isEmpty());
map.removeEntry("map");
System.out.println(map.get("map"));
System.out.println(map.containsValue(50));
System.out.println(map.get("测试"));
System.out.println(map.containsValue(100));
map.clear();
System.out.println(map.get("测试"));
System.out.println(map.containsValue(100));
}
public void clear(){
super.clear();
}
//判断是否包含某个 key
// public boolean containsKey(K key){
// return super.containsKey(new TestSimpleEntry<K, V>( key, null));
// }
public boolean containsValue(Object value){
for(TestSimpleEntry<K, V> s:this){
if(s.getValue().equals(value)){
return true;
}
}
return false;
}
//根据指定 key 获取value
public V get(Object key){
for(TestSimpleEntry<K, V> s:this){
if(s.getKey().equals(key)){
return (V) s.getValue();
}
}
return null;
}
//将制定key -value 放入集合
public V put(K key,V value){
add(new TestSimpleEntry<K, V>(key, value));
return value;
}
//另一个map 的 k-v放入该map
public void putAll(Map< K, V> map){
for(K key:map.keySet()){
add(new TestSimpleEntry<K, V>(key, map.get(key)));
}
}
//根据指定key 删除 key-value
public V removeEntry(Object key){
for(Iterator<TestSimpleEntry<K,V>> it = this.iterator();it.hasNext();){
TestSimpleEntry<K, V> simp = it.next();
if(simp.getKey().equals(key)){
V v = simp.getValue();
it.remove();
return v;
}
}
return null;
}
public int size(){
return super.size();
}
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Set2MapTest<String,Integer> map = new Set2MapTest<String, Integer>();
map.put("测试", 100);
int a= map.put("map",50);
int b = map.put("数学", 88);
map.put("数学1", 88);
System.out.println(map.put("计算机", 818)+":位置");
System.out.println(map.get("map"));
System.out.println(map.containsValue(50)+",Map大小是:"+map.size());
Set2MapTest<String,Integer> map1 = new Set2MapTest<String, Integer>();
System.out.println(map1.hashCode());
List ary = new ArrayList(2);
ary.add(1);
ary.add(2);
ary.add(3);
System.out.println("List的长度:"+ary.isEmpty());
map.removeEntry("map");
System.out.println(map.get("map"));
System.out.println(map.containsValue(50));
System.out.println(map.get("测试"));
System.out.println(map.containsValue(100));
map.clear();
System.out.println(map.get("测试"));
System.out.println(map.containsValue(100));
}
public void clear(){
super.clear();
}
//判断是否包含某个 key
// public boolean containsKey(K key){
// return super.containsKey(new TestSimpleEntry<K, V>( key, null));
// }
public boolean containsValue(Object value){
for(TestSimpleEntry<K, V> s:this){
if(s.getValue().equals(value)){
return true;
}
}
return false;
}
//根据指定 key 获取value
public V get(Object key){
for(TestSimpleEntry<K, V> s:this){
if(s.getKey().equals(key)){
return (V) s.getValue();
}
}
return null;
}
//将制定key -value 放入集合
public V put(K key,V value){
add(new TestSimpleEntry<K, V>(key, value));
return value;
}
//另一个map 的 k-v放入该map
public void putAll(Map< K, V> map){
for(K key:map.keySet()){
add(new TestSimpleEntry<K, V>(key, map.get(key)));
}
}
//根据指定key 删除 key-value
public V removeEntry(Object key){
for(Iterator<TestSimpleEntry<K,V>> it = this.iterator();it.hasNext();){
TestSimpleEntry<K, V> simp = it.next();
if(simp.getKey().equals(key)){
V v = simp.getValue();
it.remove();
return v;
}
}
return null;
}
public int size(){
return super.size();
}
}
0 0
- Set 到 Map的扩展--- 继承set
- Set 到 Map的扩展--- 实现map
- JDK集合分析Set和Map的关系(自己实现Set到Map的扩展)
- JDK集合分析Set和Map的关系(自己实现Set到Map的扩展)
- set的继承
- set, map
- map&set
- map&set
- set&&map
- List,Map,Set的区别
- List、Map、Set的区别
- map和set的排序
- List,Map,Set的区别
- List Map Set的区别
- set map list的区别
- list,set,map,的转换
- list、set、map的区别
- set和map的区别
- HTTP协议 fsockopen模拟请求代理端发送get post请求 curl基本使用
- HTML练习---新浪微博
- 矩阵快速幂-HDU5015
- javaweb 学习笔记
- jhhh
- Set 到 Map的扩展--- 继承set
- jquery.cookie() 方法的使用(读取、写入、删除)
- 数据结构预备知识(三)
- Logistic回归与梯度上升算法
- mysql 将查询结果导入表中
- linux mlockall
- Windows下 NGINX PHP 以及 "No input file specified"
- sql 去除重复记录只取一条
- 关于Genymotion下载模拟器失败