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]
[HD Pg 0, Sec. 13.3.5 - important-methods-of-arraylist]
Moderator: admin
-
- Posts: 16
- Joined: Mon Sep 30, 2019 11:40 am
- Contact:
-
- 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]
Correct.
Compare it to stringBuilder.append("a").append("b");
Compare it to stringBuilder.append("a").append("b");
Who is online
Users browsing this forum: Bing [Bot] and 16 guests