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. OleVariant Variant

    OleVariant ArrayDimCount OleVariant; System.Variants.hpp   判断OleVariant 是否为空 System::OleVariant ov i ...

  2. VB.NET条码机打印设置纸张大小的方法

    Imports System.Drawing.PrintingImports System.Runtime.InteropServices Public Class Page    <Runti ...

  3. App登录状态维持

    转载地址:http://www.jianshu.com/p/4b6b04244773 目前APP大都支持长登录,就是用户登录一次后,如果用户没有主动注销.清除APP缓存数据或卸载APP,就在一段时间内 ...

  4. lda spark 代码官方文档

    http://spark.apache.org/docs/1.6.1/mllib-clustering.html#latent-dirichlet-allocation-lda http://spar ...

  5. Linux grub命令

    一.简介 GNU GRUB(GRand Unified Bootloader简称"GRUB")是一个来自GNU项目的多操作系统启动程序.GRUB是多启动规范的实现,它允许用户可以在 ...

  6. Java 设计模式系列(十)外观模式

    Java 设计模式系列(十)外观模式 门面模式(Facade):外部与一个子系统的通信必须通过一个统一的外观对象进行,为子系统中的一组接口提供一个一致的界面,外观模式定义了一个高层接口,这个接口使得这 ...

  7. 自动创建orcl表

    using System;using System.Collections.Generic;using System.Data;using System.Linq;using System.Text; ...

  8. 关于简单的三层的简化(bll,dal,model)的封装这里全部都在一个文件主要在于明白意思

    using System;using System.Collections.Generic;using System.Linq;using System.Text; namespace 封装泛型CRU ...

  9. 利用BeanUtils.copyProperties 克隆出新对象,避免对象重复问题

    1.经常用jQuery获取标签里面值val(),或者html(),text()等等,有次想把获取标签的全部html元素包括自己也用来操作,查询了半天发现$("#lefttr1"). ...

  10. 二)quartz.properties

    The Properties File Quartz uses a properties file called (kudos on the originality) quartz.propertie ...