Store value in an Arraylist

Asked

Viewed 493 times

0

Hello, I have a question regarding storing the value I get from a table in an arraylist of arraylist. As I should do to be able to store?

For example:

Private ArrayList<ArrayList<String>> valorMatriz = new ArrayList<ArrayList<String>>();

String v;

int linha = jTable2.getRowCount();
int coluna = jTable2.getColumnCount();

for(int i = 0; i < linha; i++){
  for(int j = 0; j< coluna; j++){
     valor = jTable2.getValueAt(i,j).toString();
    //código que armazena a variável valor em valorMatriz
     print(valor + " ");
  }
}

Question: what is the syntax for storing the v variable in Triz value?

  • Are you having any problems? Everything seems okay, but I don’t know, it lacks better context.

  • 1

    It’s kind of weird, the private should have p tiny, and should have a () at the end of the first line, but if your code is like this it is not even to compile. Specify exactly what problem you are having.

  • The problem is the syntax itself, I’m not getting, although I’m looking for, a way (command) to store the value v inside of valueMatriz

  • The lack of () was only here on hr to write, but the private with p minuscule error not.

  • With the code informed you just can’t detect the problem. Add more of the implementation.

  • 2

    To string is also with wrong capitalization, should be String. It would be good for you to create a [mcve] so that it is possible to help you better.

  • I haven’t seen any problems with the code yet. You need to be more specific. How much better or worse, makes the response opinionated, the kind the site does not encourage.

Show 2 more comments

1 answer

2


ArrayList<ArrayList<String>> valorMatriz = new ArrayList<>();

String v;

int linha = jTable2.getRowCount();
int coluna = jTable2.getColumnCount();

for(int i = 0; i < linha; i++){
    ArrayList<String> arrayLinha = new ArrayList<>();
    for(int j = 0; j< coluna; j++){
        valor = jTable2.getValueAt(i,j).toString();
        arrayLinha.Add(valor);
        print(valor + " ");
    }
    valorMatriz.add(arrayLinha);
}
  • 1

    Thank you, I was able to make it work

  • 1

    @Michaelpacheco , I would like to add an addendum on Arraylist: here

Browser other questions tagged

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