Home > Back-end >  JAVA ArrayList a newline
JAVA ArrayList a newline

Time:09-25

A collection of multiple objects, print collection, how to let each object print a newline, rather than in a row

CodePudding user response:

You this is called the object's toString dozen out
The ArrayList toString is
You can write a loop to print the content in the ArrayList

CodePudding user response:

Arraylist. Stream (). The foreach (System. Out: : println)

CodePudding user response:

The set, the get method

CodePudding user response:

Piss me off, on talent!!!!!
 List List=Arrays. AsList (1, 2, 3, 4, 5); 
System. Out. Println (list);

This print will be one line of output, its output is a list the object's toString (), you can't modify the list of the toString () code, so it is the output of one line, want to solve, you can write a class inherits ArrayList, covering its toString (), and then modified into the properties of line joining together string can,

Another solution is to iterate through the collection, and then wrap the output each element, if you are using JDK is above 1.8, use the following this simple code
 List List=Arrays. AsList (1, 2, 3, 4, 5); 
List. The forEach (System. Out: : println);
  • Related