The array output format: [1, 2, 3]
Map output format map={c=a=1, b=2, 3}
The list output format list=[1, 2, 3, 4]
Here are a few questions
1. List and map are Java collection in a container, why the two different output formats, why the list using the square brackets [], rather than on behalf of the collection of {}
2. The array output is [], the list is, both of them to see if there is a relationship
3. The array output is [], why definition is
Int I=new int [] [],1,2,3 {0}, why the assignment is to use the set, and another definition of an array of int [] I=new int [6] are fundamentally different, thank you.
CodePudding user response:
1 no why, this is two different kinds of data structure, so the toString method to achieve different results (different), just as the Object and Calendar are objects, print the result is different also, can you ask why? ToString method not have to think how to implement, how to realize how to implement,2 array and list have some similarities, such as data can be accessed through the subscript, etc. (the former is only allocated memory size, which is dynamically allocated memory size, so the toString method also similar, but the list of the underlying implementation are using arrays, specific can see the source code,
{3} is not set assignment, but at the same time to the array elements in the array assignment, this form only in an array declaration of use at the same time, the statement can't assignment for array as a whole, can only separate assignment of array elements, so and new int the essence of [6] is no different, but the former initial values of the array elements is also set up, and the new int [6] each element of the initial value is the default value is 0,
CodePudding user response: