By "re-inserted" - does it mean just put again, or removed and then put again? Because I'm not sure how the insertion order is maintained if an item is removed and then inserted - wouldn't the backing linked list redirect its pointers to the before/after elements after an element is removed?Note that insertion order is not affected if a key is re-inserted into the map.
About Question enthuware.ocpjp.v8.2.1564 :
Moderator: admin
-
- Posts: 56
- Joined: Tue Feb 21, 2017 4:24 pm
- Contact:
About Question enthuware.ocpjp.v8.2.1564 :
Comment for the right option states:
-
- Site Admin
- Posts: 10036
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1564 :
It means that if the map already has a key mapped to a value and if you put a new value for the same key, the order doesn't change. Here is an example:
Code: Select all
LinkedHashMap lhm = new LinkedHashMap();
lhm.put("2", "2");
lhm.put("1", "1");
lhm.put("5", "5");
lhm.put("3", "3");
System.out.println(lhm); //prints {2=2, 1=1, 5=5, 3=3}
//lhm.remove("2"); //If you uncomment this line the output of the next line will be
//{1=1, 5=5, 3=3, 2=22} Order changes.
lhm.put("2", "22"); //prints {2=22, 1=1, 5=5, 3=3} No change in order.
If you like our products and services, please help us by posting your review here.
-
- Posts: 56
- Joined: Tue Feb 21, 2017 4:24 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1564 :
Got it, thanks!
Who is online
Users browsing this forum: Google [Bot] and 41 guests