Page 1 of 1

About Question enthuware.ocpjp.v7.2.1279 :

Posted: Tue Aug 29, 2017 5:52 pm
by thodoris.bais
Hello,

I cannot understand "//LINE 4 affects the original map as well".
I mean, tailMap is only backed from the original map and not an updatable copy, thus, to my understanding, any change made to tailMap, shouldn't affect mymap.

Regards,
Thodoris

Re: About Question enthuware.ocpjp.v7.2.1279 :

Posted: Tue Aug 29, 2017 10:46 pm
by admin
Yes, //line 4 is System.out.println(tailmap.pollFirstEntry()); //LINE 4

It doesn't refer to mymap.

HTH,
Paul.

Re: About Question enthuware.ocpjp.v7.2.1279 :

Posted: Wed Aug 30, 2017 6:17 am
by thodoris.bais
So, correct answer in this case should be "c - cat and 4" and not "c - cat and 3", as the software suggests, correct?

Re: About Question enthuware.ocpjp.v7.2.1279 :

Posted: Wed Aug 30, 2017 9:12 pm
by admin
Sorry, I misunderstood your original question. "backed by the original map" means that any changes that you do to the map will be visible to the original map from which this map was created. It does not mean that simply a back up of original map is taken to create the new map.
Since tailMap is created using mymap.tailMap method, any changes in the Map object referred to by tailMap will be reflected in mymap also.

HTH,
Paul.

Re: About Question enthuware.ocpjp.v7.2.1279 :

Posted: Sun May 27, 2018 3:42 pm
by boholstapp
I was also confused how it affects each other but I guess its a characteristic of a map that both ways have the same effect. I did not personally know this. I also tried it on a regular List collection and its the same.

package t03q55;

import java.util.*;

public class Testclass2 {

public static void main(String[] args) {

Map<String, String> map01 = new TreeMap<String, String>();
map01.put("a", "apple"); map01.put("b", "boy"); map01.put("c", "cat");

Map<String, String> map02 = map01;

System.out.println(map01);
System.out.println(map02);

System.out.println(map02.remove("a") + " IS REMOVED");

System.out.println(map01);
System.out.println(map02);

System.out.println(map01.remove("b") + " IS REMOVED");

System.out.println(map01);
System.out.println(map02);



}
}
=================================
//END RESULT:
{a=apple, b=boy, c=cat}
{a=apple, b=boy, c=cat}
apple
{b=boy, c=cat}
{b=boy, c=cat}
boy
{c=cat}
{c=cat}

Re: About Question enthuware.ocpjp.v7.2.1279 :

Posted: Thu Jul 26, 2018 4:18 am
by ArpRokz
Can someone explain how the keys are sorted in the navigable map. What role does lower case, upper case, numbers ,special characters and String length play when Strings are sorted in navigable map.

Re: About Question enthuware.ocpjp.v7.2.1279 :

Posted: Thu Jul 26, 2018 5:32 am
by admin