Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6477255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:55:34+00:00 2026-05-25T06:55:34+00:00

In my Java class, the professor uses something like: integerBox.add(new Integer(10)); Is this the

  • 0

In my Java class, the professor uses something like:

integerBox.add(new Integer(10));

Is this the same as just doing:

integerBox.add(10);

?
I’ve googled a bit but can’t find out one way or the other, and the prof was vague.
The closest explanation I can find is this:

An int is a number; an Integer is a pointer that can reference an
object that contains a number.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T06:55:35+00:00Added an answer on May 25, 2026 at 6:55 am

    Basically, Java collection classes like Vector, ArrayList, HashMap, etc. don’t take primitive types, like int.

    In the olden days (pre-Java 5), you could not do this:

    List myList = new ArrayList();
    myList.add(10);
    

    You would have to do this:

    List myList = new ArrayList();
    myList.add(new Integer(10));
    

    This is because 10 is just an int by itself. Integer is a class, that wraps the int primitive, and making a new Integer() means you’re really making an object of type Integer. Before autoboxing came around, you could not mix Integer and int like you do here.

    So the takeaway is:

    integerBox.add(10) and integerBox.add(new Integer(10)) will result in an Integer being added to integerBox, but that’s only because integerBox.add(10) transparently creates the Integer for you. Both ways may not necessarily create the Integer the same way, as one is explicitly being created with new Integer, whereas autoboxing will use Integer.valueOf(). I am going by the assumption the tutorial makes that integerBox is some type of collection (which takes objects, and not primitives).

    But in this light:

    int myInt = 10;
    Integer myInteger = new Integer(10);
    

    One is a primitive, the other is an object of type Integer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Imagine this sample java class: class A { void addListener(Listener obj); void removeListener(Listener obj);
I once wrote this line in a Java class. This compiled fine in Eclipse
This semester in university I have a class called Data Structures, and the professor
My teacher in an upper level Java class on threading said something that I
Java .class files can be decompiled fairly easily. How can I protect my database
The RFC for a Java class is set of all methods that can be
I have a java class: it.eng.ancona.view.RuoliView$TabElaborazioneFattureValidazione$ElencoDettaglioElaborazioneFattureValidazione$RigaElencoDettaglioElaborazioneFattureValidazione It's so long for multiple inner class. If
I have a java class which fires custom java events. The structure of the
I have a java class that applies an xslt to all xml files in
I have the following java class with the JAXB @XMLRootElement annotation @XmlRootElement(name=ClientData) public class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.