Converted to a String in Java output in the List

One of the easiest methods is to use the toString method which follows List

private void OutString() {
        
        List<Integer> integerList = Arrays.asList(1,2,34,6);
        System.out.println(integerList);
    }

Output:

[1, 2, 34, 6]

ToString method used herein is the List elements, used in the examples is of type integer, it toString () method.

If we are to use their own definitions, such as "Person", then pay attention to "Person" class must override the toString method returns otherwise there will be problems like this

 org.baeldung.java.lists.ListToSTring$Person@6996db8

 

Guess you like

Origin www.cnblogs.com/hwcs/p/11465123.html