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

2021-01-16 16:14

阅读:455

标签: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 list = new ArrayList15     (Arrays.asList("joker", "navi", "violet", "fox", "joker"));
16     
17     static Collection fill(Collection collection) {
18 
19         nextCollection(collection);
20 
21         return collection;
22     }
23 
24     static void nextCollection(Collection collection) {
25 
26         for (int i = 0; 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 ) {
36             array[i] = list.get(i);
37             System.out.print(array[i] + " ");
38         }
39         System.out.println();
40         System.out.println(fill(new ArrayList()));
41         System.out.println(fill(new LinkedList()));
42         System.out.println(fill(new HashSet()));
43         System.out.println(fill(new LinkedHashSet()));
44         System.out.println(fill(new TreeSet()));
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


评论


亲,登录后才可以留言!