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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:41:14+00:00 2026-05-23T17:41:14+00:00

Run time exception– java.lang.ClassCastingException … Integer intArr[] = new Integer[arrList.size()]; ArrayList <Integer> arrList =new

  • 0

Run time exception– java.lang.ClassCastingException…

Integer intArr[] = new Integer[arrList.size()];
ArrayList <Integer> arrList =new ArrayList();
intArr=(Integer[])arrList.toArray(); // returns Object class which is downcaste to Integer;

I understand down-casting is not safe but why is this happening?
I also tried to converting ArrayList to String to Integer to int, but I get the same error.

  • 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-23T17:41:14+00:00Added an answer on May 23, 2026 at 5:41 pm

    First of all, this doesn’t bind the ArrayList to type Integer.

    ArrayList <Integer> arrList =new ArrayList();
    

    Instead, this is what happens, arrList is assigned to an ArrayList of raw type, but that isn’t a problem.

    The problem lies in,

    intArr=(Integer[])arrList.toArray();
    

    since arrList is a raw-type (due to the assignment, it gets assigned as new ArrayList<Object>() by the compiler), you’re effectively getting an Object[] instead.

    Try assigning arrList to new ArrayList<Integer>() and do this:

    intArr = arrList.toArray(new Integer[arrList.size()]);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The new version AIR gives us the ability to globally capture run time errors
My app doesn't cover all the exception scenarios. During run time, sometimes a window
At run time I want to dynamically build grid columns (or another display layout)
I receive this Run-Time Check Failure upon the return in the following code. I
I need to at run time change the font of a List Control so
It looks like the run-time compiler doesn't support the same language as the command-line
How do I access an image during run time that I have added to
I'm trying to determine the asymptotic run-time of one of my algorithms, which uses
I want to discover at run-time ONLY the static Methods of a class, how
Is there a way to identify at run-time of an executable is being run

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.