About Question enthuware.ocpjp.v8.2.1564 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
lenalena
Posts: 56
Joined: Tue Feb 21, 2017 4:24 pm
Contact:

About Question enthuware.ocpjp.v8.2.1564 :

Post by lenalena »

Comment for the right option states:
Note that insertion order is not affected if a key is re-inserted into the map.
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?

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v8.2.1564 :

Post by admin »

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.

lenalena
Posts: 56
Joined: Tue Feb 21, 2017 4:24 pm
Contact:

Re: About Question enthuware.ocpjp.v8.2.1564 :

Post by lenalena »

Got it, thanks!

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 41 guests