-3

I'm having an arraylist which contains object of class X. Class x has property name & desc. When I pass this object to a method, it needs to set all class object(X) description as 'MyDescription'. What is the best way to do it.

For eg

class X{
    String name;
    String desc="Hello";
    //We have getters & setters too.
}

ArrayList<X> obj=getArraylist();

Now we got say 10 object of class X in obj. I need to reset all its description to 'MyDescription'

Can I do without looping into each object and reset its value? Please suggest.

ekad
  • 14,436
  • 26
  • 44
  • 46
MukeshKoshyM
  • 514
  • 1
  • 8
  • 16

1 Answers1

1

No, you can't do this without looping of some form.

The best way to accomplish this is to iterate of the list and set the values as needed.

BlackHatSamurai
  • 23,275
  • 22
  • 95
  • 156