java - Can someone give an explanation for this array length? -


    string  inputlist ="i dont understand this";     string[]    temp = new string[1];            temp = inputlist.split(" ");     system.out.println(temp.length); 

we can store fixed set of elements in java array. declared size of array 1 tried store 4 elements. can see size increased 4. why? can store fixed size of elements in array. doesn't grow size. why have size 4 instead of one?

string[] temp = new string[1]; 

here created array of 1 element , assigned temp variable.

temp = inputlist.split(" "); 

here assigned temp variable different array, created , returned inputlist.split(" "), can have different number of elements (4 in case).

the original 1 element array wasn't changed second assignment. however, after second assignment, no variable referring original array, can't access anymore , can garbage collected.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -