Jeff Verdegan[Or just create the "inner" String array inside the loop. [/quote wrote:
I used this method. Its works great... thanks!
Jeff Verdegan wrote:
The above puts a reference to that one single String array that was ever created into the current element of the data array.
In other words, you're only ever creating one array of Strings, and then you keep replacing its contents with the new Strings from each line, and then all the "outer" elements of your 2D array point to that same single String[] object.
You need to create a new String[] for each row.
When you do x = y with reference variables in Java, it only ever copies the reference, never the object, so the result of that assignment will simply be two reference variables pointing to the same object.
Henry Wong wrote:Remember that java technically doesn't have 2D arrays. It has arrays of arrays. So, this statement...
Is assigning the element of the outer array to point to the row array -- the previous row is now eligible for GC. And of course, by the time the loop is done, all the elements will refer to the same row array.
Henry
Roberto Perillo wrote:Greetings, Wayne. Welcome to JavaRanch!
Please CarefullyChooseOneForum when you post a question. Posting your question to the right forum helps keep it well organized, and everybody can benefit from the discussion. Since this has more to do with Java Swing, let's slide it over there