James Sabre wrote:
Akil Kumar wrote:
How can I index multiple columns of variable length while reading a CSV file? Let's say I have col A, col B, col C and so on. I want to create a 2D array with col A & B then col A & C then col A & D and so on. Moreover can any of the columns contain empty cells in between? Please help me how to achieve this?
I don't see where creating a transpose matrix comes into this and don't fully understand the requirement but it seems to me you need to use the Facade pattern. Having created your 2 D array from the CSV file you then define a class along the lines of
which defines a mapping between the cols of the original and the desired and an access method to do the conversion.
It is trivial to add methods to return the number of rows and the number of columns. It is trivial to modify the getElement() method to handle non-existent rows or columns.
You then us this as
then use the access getElement() method to access the sudo matrix.
Jesper de Jong wrote:Ofcourse that is possible. So, you want to write a program that does this? What code have you written yourself, and where exactly did you get stuck?
Philip Grove wrote:Reading multiple files regardless of format is perfectly doable, you just have to make sure not to overwrite "old" data when reading new files.
Using StringTokenizer is strongly discouraged, it's a legacy class retained for compatability reasons. Look into the split() methods of String or the java.util.regex package. While regular expressions might be difficult at first, and more so in Java as they don't use the standard POSIX syntax, it's a very powerful tool.
If you want a object doing the splitting, then look at the Scanner class of the java.util package, it does support having a String as a source.