1、容器不同于数组,容器若是想输出全部元素,可以直接利用System.out.println(collection)

public class TestCollectionArrayPrint {
public static void main(String[] args){
Collection<String> collection = new ArrayList<>();
collection.add("Test1");
collection.add("Test2");
collection.add("Test3");
System.out.println(collection);//直接打印引用数据类型变量名
}
}
/*output:
[Test1, Test2, Test3]
*/

2、数组输出全部元素:(1)利用foreach语句;(2)for循环遍历数组元素,再输出;(3)借用Arrays.toString(array)语句

public class TestCollectionArrayPrint {
public static void main(String[] args){
String[] str = {"Test1","Test2","Test3"};
System.out.println(Arrays.deepToString(str));
//借用Arrays.toString()方法
}
}
/*output:
[Test1, Test2, Test3]
*/

Java容器中的元素输出的更多相关文章

  1. 设计模式学习笔记(十六)迭代器模式及其在Java 容器中的应用

    迭代器(Iterator)模式,也叫做游标(Cursor)模式.我们知道,在Java 容器中,为了提高容器遍历的方便性,把遍历逻辑从不同类型的集合类中抽取出来,避免向外部暴露集合容器的内部结构. 一. ...

  2. 【Java心得总结六】Java容器中——Collection

    在[Java心得总结五]Java容器上——容器初探这篇博文中,我对Java容器类库从一个整体的偏向于宏观的角度初步认识了Java容器类库.而在这篇博文中,我想着重对容器类库中的Collection容器 ...

  3. 迭代器模式在 Java 容器中的实现

    迭代器接口是迭代器模式实现的精髓: public interface Iterator<E> { boolean hasNext(); E next(); ... } 假设某容器名为 Xx ...

  4. c++随机排序容器中的元素

    在各种程序语言中都提供了将容器元素随机排序的shuffle方法,c++也不例外. 不过c++将shuffle放在了<algorithm>中而不是像其他语言一样在random里,同时c++1 ...

  5. java容器中 哪些是线程安全的

    容器中线程安全的如:vectory,hashtable,非线程安全的如:hashmap,arrylist等.      对于原定义非线程的容器如:hashmap,arraylist可以使用Collec ...

  6. 如何删除JAVA集合中的元素

    经常我们要删除集合中的某些元素.有些可能会这么写. public void operate(List list){ for (Iterator it = list.iterator(); it.has ...

  7. 删除STL容器中的元素

    有关stl容器删除元素的问题,错误的代码如下: std::vector<struct> mFriendList; ... std::vector<struct>::iterat ...

  8. java项目中eclipse控制台输出log4j的信息

    最近做的一个hadoop项目中,用MR实现了一个比较复杂的问题,其中的日志信息都是使用的是log4j来处理的.但不知怎么控制台不输出日志信息,只能输出System.out.println()信息,这个 ...

  9. c++ 匹配A容器中最先出现的b容器中的元素,返回iterator,(find_first_of)

    #include <iostream> // std::cout #include <algorithm> // std::find_first_of #include < ...

随机推荐

  1. YII 自带验证码实现

    共三步,分别controllers,models,views各一层添置一行代码即可实现 第一步在controllers添加 public function actions() { return arr ...

  2. 更换windows xp序列号

    ON ERROR RESUME NEXT Dim VOL_PROD_KEY if Wscript.arguments.count<1 then VOL_PROD_KEY=InputBox(&qu ...

  3. java.lang.NoClassDefFoundError: weblogic/kernel/KernelStatus

    solution Step: 1.In the classpath tab, be sure to add the wlclient.jar file located here \wlserver_1 ...

  4. oracle 安装包

    Oracle Database 10g Release 2 (10.2.0.1.0) Enterprise/Standard Edition for Microsoft Windows (32-bit ...

  5. open()打开文件失败对应的各种错误码

    open()打开文件失败错误码: 获取错误信息实例: HANDLE hFile = ; hFile = open(“c:\test.txt”, O_RDWR, S_IRWXU|S_IRWXG|S_IR ...

  6. manjaro i3 配置笔记

    更改国内源 sudo pacman-mirrors -GB testing -c China 增加Arch linuxcn源 在/etc/pacman.conf文件末尾添加两行: [archlinux ...

  7. python's output redirect

    [python's output redirect] fin = open("xx.txt", 'r'); print >>fin, "hello world ...

  8. 64. Minimum Path Sum (Graph; DP)

    Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which ...

  9. 搭建github博客,hexo主题

    买个域名,多少钱的都有,看自己喜欢,可以去万网,ali嘛. 一般在windows,下载gitbash(配置公钥,全局用户名和email),node.js(不用配置). 新建github项目,添加公钥( ...

  10. TLB与内存寻址,内存读取,虚拟内存的相关原理

    TLB(Translation Lookaside Buffer)转换检测缓冲区是一个内存管理单元,用于改进虚拟地址到物理地址转换速度的缓存. TLB是一个小的,虚拟寻址的缓存,其中每一行都保存着一个 ...