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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:38:12+00:00 2026-05-27T11:38:12+00:00

I was working on a problem when I encountered this. (int)input.charAt(i) //works (Integer)input.charAt(i) //

  • 0

I was working on a problem when I encountered this.

(int)input.charAt(i) //works
(Integer)input.charAt(i) // Does not work
// input being a string

The first thought I have is primitives are treated differently and that is why this is not working. But then I find it difficult to understand why would they have a Integer Wrapper class in the first place.

Edit:
What are the advantages of having wrapper classes then? Is it just for not having a primitives presence and being more OO in design? I’m finding it difficult to understand how are tehy helpful. New doubt altogetehr.

  • 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-27T11:38:13+00:00Added an answer on May 27, 2026 at 11:38 am

    You’re right that primitives are treated differently. The following would work:

    (Integer)(int)input.charAt(i);
    

    The difference is that when the argument is an int, (Integer) boxes the integer. It’s not actually a cast even though it looks like it. But if the argument is a char, then it would be a cast attempt; but primitives can’t be cast to objects and therefore it doesn’t work. What you can do is to first cast the char to int – this cast is okay since both are primitive types – and then the int can be boxed.

    Of course, char -> Integer boxing could have been made working. “Why not?” is a good question. Probably there would have been little use for such feature, especially when the same function can be achieved by being a little bit more explicit. (Should char -> Long work too, then? And char -> Short? chars are 16-bit, so this would be most straightforward.)

    Answer to edit: the advantage of wrapper classes is that wrapped primitives can be treated like objects: stored in a List<Integer>, for example. List<int> would not work, because int is not an object. So maybe even more relevant question would be, what are primitive non-objects doing in an OO language? The answer is in performance: primitives are faster and take less memory. The use case determines whether the convenience of objects or the performance of primitives is more important.

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

Sidebar

Related Questions

I'm working on a practice problem set for C programming, and I've encountered this
I have the following problem that other people must have encountered. I am working
I'm working with java images for the first time and having a problem viewing
I've just encountered a rather strange problem. A Winforms (although that may not be
The problem I encountered and am unable to solve goes something like this. I
It seems that this problem has already been encountered by quite a few people:
I am currently working in a java program involving mysql. I encountered a problem
I'm writing a windows application in C++ and encountered the following problem when working
I am working on a piano in C#. I have encountered a small problem.
I'm working on a semantic web project and I've encountered some problems about Uri

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.