G
G
gleendo2017-02-23 18:19:23
Java
gleendo, 2017-02-23 18:19:23

Where are collections' toString implementations located?

Here is a sample code. A TreeSet collection is created and printed to the console. The output is the string [1, 2, 3, 4, 5, 9].
Where can I see the implementation of the toString() method in TreeSet for example? Passed from ctrl to set.toString(), but the method inherited from Object is shown. Where does this output in square brackets come from?
In general, tell me what and how with these toString(). Either I drove a little, or I really can’t understand.

import java.util.Arrays;
import java.util.Set;
import java.util.TreeSet;

public class App {
    public static void main(String ...args) {
        Set<Integer> set = new TreeSet<>(Arrays.asList(1, 2, 3, 4, 5));
        
        System.out.println(set); // [1, 2, 3, 4, 5]
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
roswell, 2017-02-23
@evgeniy8705

src.zip:java/util/AbstractCollection.java

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question