Java SE 是什么,包括哪些内容(二十一)?
本文内容参考自Java8标准
再次感谢Java编程思想对本文的启发!
首先,了解一个方法:
类Arrays的方法toString()。
你必须使用类Arrays的方法toString()来产生数组的可打印表示
容器的打印无需任何的帮助,不需要特别使用哪个方法。
代码示例:
// 容器的打印
//类PrintingContainers
public class PrintingContainers{
//方法fill(Collection<String> collection),
//带一个Collection类型的形式参数collection
//泛型类型为String,返回类型为Collection
static Collection fill(Collection<String> collection){
//往容器collection中添加字符串"rat"
collection.add("rat");
//往容器collection中添加字符串"cat"
collection.add("cat");
//往容器collection中添加字符串"dog"
collection.add("dog");
//往容器collection中添加字符串"dog"
collection.add("dog");
//返回引用collection