I need to access indexes from a java array

Asked

Viewed 67 times

0

public class Conteudo {   
public List<String> Matriz(String[] array){

    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) { 
               int var[] = new int[conteudo.size()];
                conteudo.addAll(Arrays.asList(linha.split(" ")));   
        }   
         in.close();
    } catch (IOException ioe) {
        System.out.println(ioe);
    }
        System.out.println(conteudo);
        return conteudo;

}

public void conteudo(String[] array){

}

}

I need to access the contents of this array to handle in another method.

  • public List<String> Matriz() << this method I want to take what it returns and treat in this other method public void Matriz22()

1 answer

3


At the time you added the elements in the list, you can access it like this:

conteudo.get(i) //Onde i é o índice. 

And if it is an array "String[]", then access:

String[] array = new String[10];
System.out.println(array[i]) //Onde i é o índice;

Reference here

  • But I need to treat these indexes in another method, in this method I just balance the content that comes from a txt file saved in an array "content".

Browser other questions tagged

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