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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T12:16:49+00:00 2026-05-21T12:16:49+00:00

I have the following Vector and at runtime I want to pass it an

  • 0

I have the following Vector and at runtime I want to pass it an Integer, Character, or Float:

public static Vector<Object> interestingValues = new Vector<Object>();

At the same time I want to get an Integer, Float, or Character from it, so there are two things:

  • Will they retain the specific Integer/Float/Character type in the Object Vector, or they all will be stored in the form of Object?

  • How can I retrieve Integer objects from this Vector?

  • 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-21T12:16:50+00:00Added an answer on May 21, 2026 at 12:16 pm

    Casting:

    Integer i=(Integer)interestingValues.get(0);
    

    In case you have multiple types of objects inside the Vector you could check the type using instanceof:

    Object o=interestingValues.get(0);
     if (o instanceof Integer){
          Integer i=(Integer)o;
     }else if (o instanceof Long){
          Long l=(Long)o;
     }
    

    The third thing you can do to avoid the need ov casting objects to a particular type is using a typed Vector:

    Vector <Integer> integerVector=new Vector<Integer>();
    integerVector.add(Integer.MAX_VALUE);
    Integer i=integerVector.get(0);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following existing classes: class Gaussian { public: virtual Vector get_mean() =
suppose I have this vector vector<Object> m; and then I have the following assignments:
I have the following member data vector<State<T>*> activeChildren; I want to clean-up these pointers
I have the following code snippet: vector<DEMData>* dems = new vector<DEMData>(); ConsumeXMLFile(dems); if(!udp_open(2500)) {
I have the following code (compiler: MSVC++ 10): std::vector<float> data; data.push_back(1.0f); data.push_back(1.0f); data.push_back(2.0f); //
I have the following code: vector<vector<Obj> > vectObjVects(10); vectObjVects[0].reserve(100); During runtime, at the third
I have the following data structure (an atomic vector?) output from daply in plyr
I have the following code: void foo() { vector<double> v(100,1); // line 1 //
I have the following function which creates a std::vector of iterators into another container:
I have the following template declaration: template <typename T> void IterTable(int& rIdx, std::vector<double>& rVarVector,

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.