[HD Pg 0, Sec. 13.3.5 - important-methods-of-arraylist]
Posted: Tue Nov 05, 2019 12:03 pm
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]
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]