Home java How to display an array into the java console?

How to display an array into the java console? [Duplicate]

Author

Date

Category

Instead of the output of the array itself into the console, I have this message:

[[i @ 1b6d3586
[[I @ 1b6d3586

Code itself:

Public Class Main {
  Public Static Void Main (String [] Args) {
    int [] [] MATRIX1 = NEW INT [2] [2];
    Matrix1 [0] [0] = 5;
    MATRIX1 [1] [0] = 1;
    Matrix1 [0] [1] = 4;
    Matrix1 [1] [1] = 0;
    For (int [] A: Matrix1) {
      System.Out.printLN (Matrix1);
    }
  }
}

How to fix this?


Answer 1, Authority 100%

Perhaps you do not even need a cycle to output an array on the screen:

arrays.deepTostring (Matrix1)

Answer 2, Authority 17%

for (int [] A: Matrix1)
  System.out.PrintLN (arrays.tostring (a));

Answer 3, Authority 17%

Option using Stream for two-dimensional array:

arrays.stream (Matrix) .map (Arrays :: Tostring) .Foreach (System.out :: PrintLN) ;

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions