Page 1 of 1

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

Posted: Wed Mar 06, 2013 3:42 am
by The_Nick
Are LinkedList on the OCAJP exam?



The_Nick

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

Posted: Wed Mar 06, 2013 7:40 am
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.

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

Posted: Tue Jun 25, 2013 11:01 am
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"

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

Posted: Mon Oct 28, 2013 11:56 pm
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

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

Posted: Tue Oct 29, 2013 5:22 am
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.

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

Posted: Tue Oct 29, 2013 4:34 pm
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

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

Posted: Tue Oct 29, 2013 6:22 pm
by admin
BTW, that is not required for the exam though :)

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

Posted: Mon Feb 03, 2014 8:31 am
by convertor
the same logic with String.substring()
and StringBuilder.substring()
?

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

Posted: Mon Feb 03, 2014 9:38 am
by admin
Kindly write complete question. I have no idea which logic are you talking about.
-Paul.

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

Posted: Tue Dec 09, 2014 5:34 am
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!!!!

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

Posted: Tue Dec 09, 2014 8:26 am
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.

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

Posted: Tue Mar 14, 2017 6:02 pm
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?

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

Posted: Tue Mar 14, 2017 9:40 pm
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.

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

Posted: Fri Mar 09, 2018 8:56 am
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