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 7968839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:08:28+00:00 2026-06-04T07:08:28+00:00

I came across a class using Integer variables to capture size to be used

  • 0

I came across a class using Integer variables to capture size to be used in a for loop. Is this good practice or should we use the int primitive data type?

Integer size = something.getFields().size();
for (Integer j = 0; j < size - 1; ++j) 
  • 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-06-04T07:08:29+00:00Added an answer on June 4, 2026 at 7:08 am

    the Integer class is provided so that values can be boxed/unboxed in a pure OO manner. use int where appropriate unless you specifically need to use it in an OO way; in which case Integer is appropriate.

    Java Int vs Integer

    However, very different things are going on under the covers here. An int is a number; an > Integer is a pointer that can reference an object that contains a number.

    …

    An int is not an object and cannot passed to any method that requires
    objects. A common case is in using the provided collection classes (
    List , Map , Set ) – though it is possible to write versions of these
    classes that provide similar capabilities to the object versions. The
    wrapper classes ( Integer , Double , etc) are frequently required
    whenever introspection is used (such as in the reflection API).

    A better description of when to use one vs. the other:

    Choosing between int and Integer

    I’ll start with how these types should be used before going into
    detail on why.

    • Prefer int for performance reasons
    • Methods that take objects (including generic types like List<T>)
      will implicitly require the use of Integer
    • Use of Integer is relatively cheap for low values (-128 to
    1. because of interning – use Integer.valueOf(int) and not new
      Integer(int)
    • Do not use == or != with Integer types
    • Consider using Integer when you need to represent the
      absence of a value (null)
    • Beware unboxing Integer values to int with null values
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So, while using IDA to disassemble a dll, I came across this class function:
I came across this code. class SomeClass::OtherClass : public BaseClass { // stuff in
I came across this article on Code Project that talks about using an abstract
I came across the following issue: I have this model public class Region {
While writing some code i came across this issue: #include <iostream> class random {
What is scchema importer Extension class in .net webservice.Recently i came across this class
I've been successfully using MEF to obtain exported class instances. However, I came across
Today i was writing some heavy reflection-using code, and i came across this behavior
I came across this messaging tutorial recently, and was intrigued by the use of
I came across this class java.io.FileSystem and noticed it has many methods that I

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.