Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Basically, Java collection classes like <code>Vector</code>, <code>ArrayList</code>, <code>HashMap</code>, etc. don't take primitive types, like <code>int</code>.</p> <p>In the olden days (pre-Java 5), you could not do this:</p> <pre><code>List myList = new ArrayList(); myList.add(10); </code></pre> <p>You would have to do this:</p> <pre><code>List myList = new ArrayList(); myList.add(new Integer(10)); </code></pre> <p>This is because <code>10</code> is just an <code>int</code> by itself. <code>Integer</code> is a class, that wraps the <code>int</code> primitive, and making a <code>new Integer()</code> means you're really making an object of type <code>Integer</code>. Before autoboxing came around, you could not mix <code>Integer</code> and <code>int</code> like you do here.</p> <p>So the takeaway is:</p> <p><code>integerBox.add(10)</code> and <code>integerBox.add(new Integer(10))</code> will result in an <code>Integer</code> being added to <code>integerBox</code>, but that's only because <code>integerBox.add(10)</code> transparently creates the <code>Integer</code> for you. Both ways may not necessarily create the <code>Integer</code> the same way, as one is explicitly being created with <code>new Integer</code>, whereas autoboxing will use <code>Integer.valueOf()</code>. I am going by the assumption the tutorial makes that <code>integerBox</code> is some type of collection (which takes objects, and not primitives).</p> <p>But in this light:</p> <pre><code>int myInt = 10; Integer myInteger = new Integer(10); </code></pre> <p>One is a primitive, the other is an object of type <code>Integer</code>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload