首页 > 代码库 > Java 之容器学习(接上篇)
Java 之容器学习(接上篇)
/** * * 再谈容器 * @author gao */ package com.gao.thinkinjava; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.LinkedList; import java.util.Map; import java.util.TreeMap; import java.util.TreeSet; public class PrintingContainers { static void Print(Object c){ System.out.println(c); } static Collection fill(Collection<String>collection){ collection.add("rat"); collection.add("cat"); collection.add("dog"); collection.add("dog"); return collection; } static Map fill(Map<String,String>map){ map.put("rat","Fuzzy"); map.put("cat", "Rags"); map.put("dog", "Bosco"); map.put("dog", "spot"); return map; } public static void main(String[]args){ Print(fill(new ArrayList<String>())); Print(fill(new LinkedList<String>())); Print(fill(new HashSet<String>())); Print(fill(new TreeSet<String>())); Print(fill(new LinkedHashSet<String>())); Print(fill(new HashMap<String,String>())); Print(fill(new TreeMap<String,String>())); Print(fill(new LinkedHashMap<String,String>())); } }
输出结果:
[rat, cat, dog, dog] [rat, cat, dog, dog] [cat, dog, rat] [cat, dog, rat] [rat, cat, dog] {cat=Rags, dog=spot, rat=Fuzzy} {cat=Rags, dog=spot, rat=Fuzzy} {rat=Fuzzy, cat=Rags, dog=spot}
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。