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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:31:24+00:00 2026-06-15T01:31:24+00:00

i am facing problem with the retyping the object to integer. I have the

  • 0

i am facing problem with the retyping the object to integer.

I have the object Car with 2 string attributes. First attribute is ID.
I retyped ID from string to integer

ArrayList<Car> intList = new ArrayList<Car>(); // already filled with objects 

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

for(Car tempInt : items){   
intList.add(Integer.parseInt(tempInt.getID()));
}
Collections.sort(intList); // i sorted id's

Can i retype the integer back to Car object?

for (ItemObject temp : intList) { // HERE I GET THE ERROR

if(temp instanceof Car){
System.out.println("ID : "+((Car)temp).getID())
        }}

Is this possible? I need sort objects.
Thanks.
S

  • 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-15T01:31:26+00:00Added an answer on June 15, 2026 at 1:31 am

    I think you are fundamentally misunderstanding which objects are which in this scenario. When you create your ArrayList<Integer> you do not magically preserve any information about which cars those integers were connected to.

    I think what you want to do is sort your list of Cars by id, correct? In that case, what you want is a Comparator: http://docs.oracle.com/javase/6/docs/api/java/util/Comparator.html

    Here is an example of sorting using a Comparator:

    ArrayList<Car> cars = ...//Filled with cars
    Comparator<Car> carSorter = new Comparator<Car>() {
      @Override
      public int compare(Car a, Car b) {
        return a.getID() - b.getID();
      }
    };
    Collections.sort(cars, carSorter);//After this line, cars will be in order
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am facing problem to get variable from query string. I have used htaccess
I have facing problem in listview i am getting data from server and after
I want to concatenate a string but i am facing problem. Actually i have
I have facing problem for creating a Regex that accept any string other than
I am facing problem in receiving email. I have a registration form, when form
I'm facing problem when migrate my web app project from development server to live
I'm facing problem in showing FolderBrowserDialog instance created and called from a non-UI thread.
I have facing problem to access xmlrpc. Whenever I tried to access xmlrpc through
I am facing problem with Inner join in Access Database. I have two table
I have developed some code, and I'm facing problem with error flagging of the

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.