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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:52:03+00:00 2026-05-23T06:52:03+00:00

Somebody asked me: can an array in java contain integers and floats? She got

  • 0

Somebody asked me: can an array in java contain integers and floats? She got that question from a teacher.

Now my answer was: yes, since you can declare an array of objects and store integers and floats in it.

But now I’m wondering if that is correct, since technically when you store Integer and Float objects in an array, it kind of does contain both types, but if you would “ask” the array he would tell you he contains Objects, and if I don’t do bookkeeping or class checks there’s no way to tell that there are integers and floats in the array.

On the other hand I still feel it might be the right answer since theoretically the array contains objects of both types.

So I’m asking for a smart opinion: if you were asked (in an interview, a test whatever) wether in java an array can contain integers and floats, yes or no? What would you answer?

  • 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-23T06:52:03+00:00Added an answer on May 23, 2026 at 6:52 am

    A int of float does not fit into a Object[] array. However, by autoboxing java will put a Float or Integer into the array instead.

    Both Float and Integer extend Number. So you can even make a array of numbers Number[]

    Also, you can put a int into a float[], but java will then cast the int into a float. The other way around is also possible, but precision will be lost. (edit: Even from int->float precision can be lost. float->int may lose information about the overall magnitude of the value).

    The conclusion would depend on the question. For primitive datatypes a array can not contain the other datatype. If you use a Object array (Integer, Float, Number) the answer would be yes.

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

Sidebar

Related Questions

Somebody asked similar question not long ago. But nobody answered comprehensively. Assume I have:
I have looked around here to see if somebody has asked this question before
I guess this question has been asked a lot around. I know Rails can
I'm sure this has already been asked, so if somebody can refer me to
Somebody asked me this question: Two processes P1 and P2 are using a shared
Here is my problem. I already asked that question in the XAMPP community forum
Somebody already asked how you can get git to follow symlinks. There was an
Now I know this has been asked before. But I've made doubly sure that
I know that this question is asked for many times but i am working
I initially asked this on Superuser, but somebody advised me to repost here. 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.