About Question enthuware.ocpjp.v7.2.1279 :

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

Moderator: admin

Post Reply
thodoris.bais
Posts: 25
Joined: Sat Jun 03, 2017 4:56 pm
Contact:

About Question enthuware.ocpjp.v7.2.1279 :

Post 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

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

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

Post by admin »

Yes, //line 4 is System.out.println(tailmap.pollFirstEntry()); //LINE 4

It doesn't refer to mymap.

HTH,
Paul.
If you like our products and services, please help us by posting your review here.

thodoris.bais
Posts: 25
Joined: Sat Jun 03, 2017 4:56 pm
Contact:

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

Post 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?

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

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

Post 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.
If you like our products and services, please help us by posting your review here.

boholstapp
Posts: 1
Joined: Mon May 21, 2018 2:33 pm
Contact:

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

Post 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}

ArpRokz
Posts: 15
Joined: Sun Jan 28, 2018 12:38 pm
Contact:

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

Post 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.

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

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

Post by admin »

If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 42 guests