About Question enthuware.ocajp.i.v7.2.1264 :

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

Moderator: admin

Post Reply
The_Nick

About Question enthuware.ocajp.i.v7.2.1264 :

Post by The_Nick »

Are LinkedList on the OCAJP exam?



The_Nick

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

Re: About Question enthuware.ocajp.i.v7.2.1264 :

Post by admin »

The exam objectives specifically mention only ArrayList. However, some students have reported LinkedList used in some cases without affecting the answers. So you need not study much about it except that it exists.

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

prateeks
Posts: 3
Joined: Sun Jun 23, 2013 10:48 am
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1264 :

Post by prateeks »

sublist(1 , 1) should return "c" in sublist , as s1 is now = "a","c","b".
So, there are elements at index 1 i.e. "c"

javanaut
Posts: 22
Joined: Wed Aug 21, 2013 12:29 am
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1264 :

Post by javanaut »

Hi all,

if subList(int start, int end) has the first parameter, start, as inclusive and the second parameter, end, as exclusive why doesn't this throw an IndexOutOfBoundsException?

Since 1 is actually position 2, because arrays are zero based, and 1 exclusive is position 0 shouldn't this throw an exception or something since the end index is before the beginning? :shock:

Regards,

Javanaut

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

Re: About Question enthuware.ocajp.i.v7.2.1264 :

Post by admin »

What call exactly do you think should throw IndexOutOfBoundsException?
Regardless, this depends on how the method is coded. You can check out the source code for sublist method and see how exactly it treats the end index and know how it avoids the exception.

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

javanaut
Posts: 22
Joined: Wed Aug 21, 2013 12:29 am
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1264 :

Post by javanaut »

Paul,

I will have to dig into the source code for this method and see what is preventing the runtime exception. Thank-you for the reply.

Thank-you for the reply,

Kyle

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

Re: About Question enthuware.ocajp.i.v7.2.1264 :

Post by admin »

BTW, that is not required for the exam though :)
If you like our products and services, please help us by posting your review here.

convertor
Posts: 7
Joined: Mon Jan 27, 2014 6:25 am
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1264 :

Post by convertor »

the same logic with String.substring()
and StringBuilder.substring()
?

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

Re: About Question enthuware.ocajp.i.v7.2.1264 :

Post by admin »

Kindly write complete question. I have no idea which logic are you talking about.
-Paul.
If you like our products and services, please help us by posting your review here.

gparLondon
Posts: 63
Joined: Fri Oct 31, 2014 6:31 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1264 :

Post by gparLondon »

In order to answer this question, we should know the method subList(). I thought the answer may be a c b c. Thinking subList() will return c. How many such methods should we know from List interface for this exam? I have never come across list to be a part of exam objective, in any of the books!!!!

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

Re: About Question enthuware.ocajp.i.v7.2.1264 :

Post by admin »

You should know about the following methods, not because they are in List but because they are in ArrayList, which is on the exam:
add
addAll
remove
removeAll
sublist
retainAll
get
contains
clear
size
HTH,
Paul.
If you like our products and services, please help us by posting your review here.

dxie1154
Posts: 9
Joined: Sat Jan 14, 2017 5:01 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1264 :

Post by dxie1154 »

I am a bit confused on how a, c, b is printed.
I originally thought a, c, b, c would be printed because the subList() method would return c, due to the fact that subList's starting value is inclusive, and the first value is c, so it should include the String c.
Why is a, c, b printed but not a, c, b, c?

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

Re: About Question enthuware.ocajp.i.v7.2.1264 :

Post by admin »

If fromIndex and toIndex are equal (as is the case in this question), subList returns empty list. This is as per https://docs.oracle.com/javase/8/docs/a ... t-int-int-

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

Rick84
Posts: 12
Joined: Tue Mar 06, 2018 9:54 am
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1264 :

Post by Rick84 »

As background information; here are some notes by Edsger Dijkstra on why ranges should be expressed as lower <= x < upper

https://www.cs.utexas.edu/users/EWD/tra ... WD831.html

Post Reply

Who is online

Users browsing this forum: No registered users and 54 guests