Reputation: 1222
Can i update one attribute
in all object in a LIST
with a same value when the LIST
is loaded, without a loop
?`
List<E>myList= new ArrayList<>();
Map<String,List<E>>map;
myList.add(object);// object{attr1,attr2,attr3}
myList.size();//40
//traitement
map.put(key,myList);
//444+23=[object[attr1=value1, attr2= null, attr3=value3] , object[attr1=value4, attr2= null, attr3=value5]]
map.get(key).set(myList.attr2,value6);
//result
//444+23=[object[attr1=value1, attr2= value6, attr3=value3] , object[attr1=value4, attr2= value6, attr3=value5]]
Upvotes: 0
Views: 37
Reputation: 6985
If you have an ArrayList
you can use ArrayList#set
: http://docs.oracle.com/javase/8/docs/api/java/util/ArrayList.html#set-int-E-
edit: If you're talking about mutating an attribute on every object in the list, then no, you can't do it without some kind of traversal over the entire list.
Upvotes: 1