码迷,mamicode.com
首页 > 编程语言 > 详细

[20-05-20][Thinking in Java 30]Java Container 2 - Print of Container

时间:2020-05-20 17:13:02      阅读:52      评论:0      收藏:0      [点我收藏+]

标签:void   set   ext   return   pre   new   java   ring   OLE   

 1 package test_17_4;
 2 
 3 import java.util.ArrayList;
 4 import java.util.Arrays;
 5 import java.util.Collection;
 6 import java.util.HashSet;
 7 import java.util.LinkedHashSet;
 8 import java.util.LinkedList;
 9 import java.util.List;
10 import java.util.TreeSet;
11 
12 public class Creater {
13 
14     static List<String> list = new ArrayList<String>
15     (Arrays.asList("joker", "navi", "violet", "fox", "joker"));
16     
17     static Collection fill(Collection<String> collection) {
18 
19         nextCollection(collection);
20 
21         return collection;
22     }
23 
24     static void nextCollection(Collection<String> collection) {
25 
26         for (int i = 0; i < list.size(); i++) {
27             collection.add(list.get(i));
28 
29         }
30 
31     }
32 
33     public static void main(String[] args) {
34         String[] array = new String[list.size()];
35         for (int i = 0; i < array.length; i++) {
36             array[i] = list.get(i);
37             System.out.print(array[i] + " ");
38         }
39         System.out.println();
40         System.out.println(fill(new ArrayList<String>()));
41         System.out.println(fill(new LinkedList<String>()));
42         System.out.println(fill(new HashSet<String>()));
43         System.out.println(fill(new LinkedHashSet<String>()));
44         System.out.println(fill(new TreeSet<String>()));
45     }
46 
47 }

 

结果如下:

joker navi violet fox joker
[joker, navi, violet, fox, joker]
[joker, navi, violet, fox, joker]
[navi, violet, joker, fox]
[joker, navi, violet, fox]
[fox, joker, navi, violet]

[20-05-20][Thinking in Java 30]Java Container 2 - Print of Container

标签:void   set   ext   return   pre   new   java   ring   OLE   

原文地址:https://www.cnblogs.com/mirai3usi9/p/12924657.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!