H
Hal Vaughan
I have a class that reads data from a table and returns a 2D String[][].
There are a number of times when it'll only need one column of data, in
which case, a single array (String[]) would do. The method that will be
doing this has enough in it that might change that I don't want to write 2
different methods. I've considered the idea that at one point I can
combine the multiple column fields into a tab separated String, but then I
need to iterate through the first array a 2nd time and split each line.
Is there some way I can return a String[][], then if I only need one column
of data, to get just the first element of each secondary array? For
instance, get rowData[0][0], rowData[1][0], rowData[2][0], rowData[3][0],
without iterating through the entire array of data?
Every way I can think of means going through the table, getting the data,
and creating a 1D or 2D array, then having to iterate through it again to
convert if it's not what I need that time, or writing 2 separate methods.
Since this is part of the GUI, I want to keep it as fast as possible. I
considered using two objects, one String[] and one String[][], making them
global to that class and subclasses (which would help in other areas, as
well), calling the method to fill them with data, then reading whichever
one I need, but as I understand it, that's not thread safe and can result
in problems under Swing. One thread could call the method, fill up the
data, and try to read it while another thread is refilling it with
different data. (Or do I misunderstand that?)
Thanks for any suggestions, pointers, URLs, or help on this.
Hal
There are a number of times when it'll only need one column of data, in
which case, a single array (String[]) would do. The method that will be
doing this has enough in it that might change that I don't want to write 2
different methods. I've considered the idea that at one point I can
combine the multiple column fields into a tab separated String, but then I
need to iterate through the first array a 2nd time and split each line.
Is there some way I can return a String[][], then if I only need one column
of data, to get just the first element of each secondary array? For
instance, get rowData[0][0], rowData[1][0], rowData[2][0], rowData[3][0],
without iterating through the entire array of data?
Every way I can think of means going through the table, getting the data,
and creating a 1D or 2D array, then having to iterate through it again to
convert if it's not what I need that time, or writing 2 separate methods.
Since this is part of the GUI, I want to keep it as fast as possible. I
considered using two objects, one String[] and one String[][], making them
global to that class and subclasses (which would help in other areas, as
well), calling the method to fill them with data, then reading whichever
one I need, but as I understand it, that's not thread safe and can result
in problems under Swing. One thread could call the method, fill up the
data, and try to read it while another thread is refilling it with
different data. (Or do I misunderstand that?)
Thanks for any suggestions, pointers, URLs, or help on this.
Hal