1 Reply Latest reply on Nov 20, 2009 12:21 PM by 843789

    Separating columns of text file into array

      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.

        • 1. Re: Separating columns of text file into array
          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
          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:
            {1A, 1B, 1C, 1D}
            {2A, 2B, 2C, 2D}
            {3A, 3B, 3C, 3D}
          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.