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

  • Home
  • SEARCH
  • 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 7807781
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T02:57:37+00:00 2026-06-02T02:57:37+00:00

This a section of my Java program I’ve taken out and simplified to test.

  • 0

This a section of my Java program I’ve taken out and simplified to test. The task is to compare two integers from an ArrayList and state whether they are equal.

The below code works for numbers <128 but any number >128 and the code will not work.

Any help would be really great,
thanks.

import java.util.*;

public class test
{
public static void main (String[] args)
{

Integer seat1Store = 128;
Integer seat2Store = 128;
Integer seat3Store = 0;
Integer seat4Store = 0;
Integer seat5Store = 0;


ArrayList<Integer> proceedArray = new ArrayList<Integer>();


if (seat1Store !=0)
{
    proceedArray.add(seat1Store);
}
if (seat2Store !=0)
{
    proceedArray.add(seat2Store);
}
if (seat3Store !=0)
{
    proceedArray.add(seat3Store);
}
if (seat4Store !=0)
{
    proceedArray.add(seat4Store);
}
if (seat5Store !=0)
{
    proceedArray.add(seat5Store);
}

System.out.println("ArrayList = " + proceedArray);


boolean proceed = false;


for(int i = 0; i<proceedArray.size();i++)
{
    for(int p=0; p<proceedArray.size(); p++)
    {
        if(i != p)
        {
            if(proceedArray.get(i) == proceedArray.get(p))
            {
                System.out.println("DUPLICATE");
                System.exit(0);
            }
        }
    }
    proceed = true;
}


if (proceed == true)
{
    System.out.println("PROCEEDED");
}




}
}
  • 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-02T02:57:39+00:00Added an answer on June 2, 2026 at 2:57 am

    Yes, that’s expected. You should not compare object references with == or !=. You should use .equals(..) instead, or better – use the primitive int rather than Integer.

    The thing is, values up to 128 are cached, and the JVM gives you the same objects (hence the reference comparison works). Above 128 it creates a new instance. Look at the javadoc of Integer.valueOf(int) (which is what happens behind the scene)

    Returns a Integer instance representing the specified int value. If a new Integer instance is not required, this method should generally be used in preference to the constructor Integer(int), as this method is likely to yield significantly better space and time performance by caching frequently requested values.

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

Sidebar

Related Questions

So for my current program, I am currently doing this: Java Code ArrayList<Section> aMainSection
Ok, my program in this specific section takes a line of data from a
I hava a java program, a section of it is compute intensive, like this
This is a section from Core Java 8th edition Page 757 CAUTION: public void
Reading Java Concurrency In Practice, there's this part in section 3.5: public Holder holder;
I'm wondering why this code section prints out the following: print request.user.has_perm('bug_tracking.is_developer'): + str(request.user.has_perm('bug_tracking.is_developer'))
I have a java program where I am collecting entries from a user. The
This section of the GAE/Java documentation is killing me. I would appreciate if someone
From the Java Language Specification (third edition), section 3.10.5 : StringLiteral: StringCharacters opt StringCharacters:
From the Java Language Specification, Section 3.10.5 String Literals : Characters may be represented

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.