Loading...
Logo
Processing Forum
Is there an easier way to get a single parameter from a given object in an ArrayList?  Right now I'm doing it like this:

xpos = getXpos(id - 1) + 1;

int getXpos (int listnum) {
  MyClass foo = (MyClass) mylist.get(listnum);
  return foo.xpos;
}

I'd rather do it like this, though:

xpos = mylist[id -1].xpos + 1;

Any way?

Replies(2)

Yep.
Copy code
  1. ArrayList<MyClass> myList = new ArrayList<MyClass>();
  2. myList.add(new MyClass());
  3. float xPos = myList.get(0).xpos + 1;