Pass Array String by parameter

Asked

Viewed 220 times

-1

public List<String> Matriz(){

    String CaminhoArquivo=("C:\\Users\\jessica borges"
            + "\\Downloads\\CalculadoraMatrizes-20190315T112959Z-001"
            + "\\CalculadoraMatrizes-20190315T112959Z-001"
            + "\\CalculadoraMatrizes\\src\\ArquivosMatriz\\matrix.txt");

    List<String> conteudo = new ArrayList<>(); 
        try {
        BufferedReader in = new BufferedReader(new FileReader(CaminhoArquivo));
        String linha;
        while ((linha = in.readLine()) != null) { 
            conteudo.addAll(Arrays.asList(linha.split(" ")));
        }   
         in.close();             
        } catch (IOException ioe) {
            System.out.println(ioe);
            }

        System.out.println(conteudo);             
        return conteudo;     
}    

This above method adds what I want in the array, I want to treat its return in another method that follows below:

public void Matriz22(){


}

I’ve tried many ways but I can’t.

1 answer

0


For the Matriz22 method to receive a String list is like this:

public void Matriz22(List<String> lista){

}

You have not shown the class to which the Matrix() method belongs, so improvisei, to pass the return list of the Matrix() method does so:

public static void main(String[] args) {
    Classe classe = new Classe();
    List<String> lista = classe.Matriz();
    classe.Matriz22(lista);
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.