《Java编程思想》 -- 持有对象 -- 容器的打印

发布时间:2019-11-20 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了《Java编程思想》 -- 持有对象 -- 容器的打印脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

从代码中看基本类型的容器:

public class PrintingContainers {     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 LinkedHashMap<String, 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] {cat=Rags, dog=Spot, rat=Fuzzy} {cat=Rags, dog=Spot, rat=Fuzzy} {rat=Fuzzy, cat=Rags, dog=Spot}   */
  • ArrayList:插入顺序和输出顺序一致,可以重复

  • LinkedList:插入顺序和输出顺序一致,可以重复

  • HashSet:插入顺序和输出顺序不一致,不重复

  • TreeSet:插入顺序和输出顺序不一致,不重复

  • HashMap:键值对存储,键不重复。

  • TreeMap:键值对存储,键不重复。

  • LinkedHashMap:键值对存储,键不重复。

脚本宝典总结

以上是脚本宝典为你收集整理的《Java编程思想》 -- 持有对象 -- 容器的打印全部内容,希望文章能够帮你解决《Java编程思想》 -- 持有对象 -- 容器的打印所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。