[HD Pg 0, Sec. 13.3.5 - important-methods-of-arraylist]

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

Moderator: admin

Post Reply
demetrio
Posts: 16
Joined: Mon Sep 30, 2019 11:40 am
Contact:

[HD Pg 0, Sec. 13.3.5 - important-methods-of-arraylist]

Post by demetrio »

I tried to run the example in page 340 and I got "boolean cannot be dereferenced". Is that what you mean by "Method chaining: Unlike StringBuilder, none of the ArrayList methods return a reference to the same ArrayList object. Therefore, it is not possible to chain method calls"? Kindly, see tentative bellow.

Deshmukh, Hanumant. OCP Oracle Certified Professional Java SE 11 Programmer I Exam Fundamentals 1Z0-815: Study guide for passing the OCP Java 11 Developer Certification Part 1 Exam 1Z0-815 (p. 340). Enthuware. Edição do Kindle.

jshell> var al = new ArrayList < Integer >();
...> al.add( 1).add( 2);
al ==> []
| Error:
| boolean cannot be dereferenced
| al.add( 1).add( 2);
| ^------------^

jshell> all.add(1);
| Error:
| cannot find symbol
| symbol: variable all
| all.add(1);
| ^-^

jshell> al.add(1);
$3 ==> true

jshell> al.add(1).add(2);
| Error:
| boolean cannot be dereferenced
| al.add(1).add(2);
| ^-----------^

jshell> al.add(2);
$4 ==> true

jshell> System.out.println(al);
[1, 2]

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

Re: [HD Pg 0, Sec. 13.3.5 - important-methods-of-arraylist]

Post by admin »

Correct.
Compare it to stringBuilder.append("a").append("b");

Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests