Win a copy of Real-World Software Development: A Project-Driven Guide to Fundamentals in Java this week in the Agile and Other Processes forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Liutauras Vilda
  • Knute Snortum
  • Bear Bibeault
Sheriffs:
  • Devaka Cooray
  • Jeanne Boyarsky
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • salvin francis
Bartenders:
  • Tim Holloway
  • Piet Souris
  • Frits Walraven

Sybex OCA - chapter 3 #26 - I do not agree key

 
Greenhorn
Posts: 3
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wrote this code:
import java.util.*;
public class TestChapter3_26 {
 public static void main(String[] args) {
   List<Integer> ages = new ArrayList<>();
   ages.add(Integer.parseInt("5"));
   ages.add(Integer.valueOf("6"));
   ages.add(7);
   //ages.add(null);
   for (int age : ages) System.out.print(age);
 }
}

respons is:
567

why key is 'D'? I think correct key is 'E'.
 
author & internet detective
Posts: 39880
798
Eclipse IDE VI Editor Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Confused. There is no "key" in  your code.
 
hiroki inoue
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry I do not know very well English.
In the book OCA Oracle Certified Associate Java SE 8 Programmer I STUDY GUIDE, in page 342 the answer of 26 is A, B, D.
I think the answer is A, B, E.
 
Jeanne Boyarsky
author & internet detective
Posts: 39880
798
Eclipse IDE VI Editor Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah, this is from the book. I didn't pick up on that. (I've edited your subject to make it clearer).

Option D says exactly two of the add statements use autoboxing. Option E says exactly three of the add statements use autoboxing.

valueOf() method returns an Integer. Therefore it does not use autoboxing.  The other two do. Hence D is correct.
 
hiroki inoue
Greenhorn
Posts: 3
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah, 'Autoboxing'!
5 <- autoboxing
6 <- boxing
7 <- autoboxing

I understand! Thank you!
 
Jeanne Boyarsky
author & internet detective
Posts: 39880
798
Eclipse IDE VI Editor Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

hiroki inoue wrote:Ah, 'Autoboxing'!
5 <- autoboxing
6 <- boxing
7 <- autoboxing


Not quite. 6 doesn't have autoboxing or boxing. It's already an object so no conversion is needed
 
He got surgery to replace his foot with a pig. He said it was because of this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!