java如何将各种类型的数组直接打印输出

直接通过Arrays集合工具类提供的如下方法,来实现将各种类型的数组输出打印:

Arrays.asList(数组);

Arrays.toString(数组);

如果要将int数组打印出来,可以使用Arrays.toString。 
下面有一个小例程:

package testArray;

import java.util.Arrays;

public class testArray {
    public static void main(String[] args) {
        int [] a = new int[5];
        int [] b = {
  1,45,65,345};
        String[] c = {
  "dewd","fwefew","fewf"};
        for(int i = 0; i < 5; i ++){
            a[i] = i;
        }
        System.out.println("数组A: " + Arrays.asList(a));
        System.out.println("数组B: " +Arrays.toString(b));
        System.out.println("字符串C: " +Arrays.toString(c));
        System.out.println("字符串C: " +Arrays.asList(c));
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18

输出结果: 
数组A: [[I@28084850] 
数组B: [1, 45, 65, 345] 
字符串C: [dewd, fwefew, fewf] 
字符串C: [dewd, fwefew, fewf]

    原文作者:mxd446814583
    原文地址: https://blog.csdn.net/mxd446814583/article/details/79591672
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞