1 Reply Latest reply: Nov 20, 2009 6:21 AM by 843789 RSS

    Separating columns of text file into array

    843789
      Hi,
      I have a text file with four columns separated by spaces. After i have imported this into a string can anyone tell me how i could separate the columns into columns of an array? Or should this be done in the importing stage?

      Any help would be appreciated.

      Thanks
        • 1. Re: Separating columns of text file into array
          843789
          It's not clear to me what it is exactly that you are trying to achieve.
          From what I understand the text file is formatted like so:
          1A 1B 1C 1D
          2A 2B 2C 2D
          3A 3B 3C 3D
          etc.
          Is your intent to seperate the individual columns into four distinct arrays like:
          String[] {1A, 2A, 3A, etc.}
          String[] {1B, 2B, 3B, etc.}.
          String[] {1C, 2C, 3C, etc.}
          String[] {1D, 2D, 3D, etc.}
          Or would you like to store them in a similar grid pattern to the text file, using a "two dimensional" array (array of arrays) like:
          String[][] 
          {
            {1A, 1B, 1C, 1D}
            {2A, 2B, 2C, 2D}
            {3A, 3B, 3C, 3D}
            etc.
          }
          In any case, have a look at java.util.Scanner and String.split(), have a go at it, and let us know what problems you run into, if any.