Answer the question
In order to leave comments, you need to log in
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
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question