How to store split strings in an ArrayList?

1

I'm doing a job where I need to save the information for a checking account, I need to read the information in a file (text) and split this information to divide it into account code , name and balance . Also, I need to save this information in an Array.

My problem is this: I can not splice this information to save in an Array. Could you help me?

I created a function reader ();

public void leitor() throws FileNotFoundException, IOException{ 
    try (
             BufferedReader reader = new BufferedReader (new FileReader ("arquivo.txt"));
        ) {
             for (String line = reader.readLine(); line != null; line = reader.readLine()) {
                 **String saida = line.split(";");**
                 System.out.println(saida);
             }
        }
}

It only reads the information from the file, however, I can not splice this information.

    
asked by anonymous 31.03.2017 / 16:09

2 answers

1

See a simple way using the static method Arrays.asList() , but "splintando" spaces:

String str = "A HBO anunciou a sétima temporada de Game of Thrones";       
ArrayList<String> arrayList = new ArrayList<String>(Arrays.asList(str.split(" ")));

To be separated by a semicolon, but to place .split(";") ;

    
31.03.2017 / 16:57
-3

Instead of doing String saida = line.split(";");

does

var saida = line.split(';');

or else you declare string[] saida

    
31.03.2017 / 16:16