0

I have written only necessary information to make you understand the error. I have a multiple arraylist(specification) i.e.

speci={{node,node},{node,node}}

The node is an object that contains an int and a boolean i.e.

node= int value , boolean explored

I wanted to access the int of the node object through following way,

System.out.println(speci.get(0).get(0).value); // IDE is not accepting it, suggest a way

My IDE(NetBeans8.1) is not accepting, saying cannot find symbol value. How can I access that value using ArrayList? TIA :-)

1 Answers1

0

Within your node class define getter for the fields and then use -

System.out.println(speci.get(0).get(0).getValue());

Under an assumption, that speci is somewhat -

ArrayList<ArrayList<node>> speci;

and node(would suggest renaming this to Node instead) would be like -

public class Node {
    int value;
    ... // other attributes
    int getValue() {
        return value;
    }
    ...// other getters and setters
}

Here is a useful link on Why use getters and setters?

Community
  • 1
  • 1
Naman
  • 27,789
  • 26
  • 218
  • 353