[20-05-20][Thinking in Java 30]Java Container 2 - Print of Container
Posted mirai3usi9
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[20-05-20][Thinking in Java 30]Java Container 2 - Print of Container相关的知识,希望对你有一定的参考价值。
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的主要内容,如果未能解决你的问题,请参考以下文章
Hacker Rank: Two Strings - thinking in C# 15+ ways
Thinking in Java & Writing in Python