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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T03:57:28+00:00 2026-06-11T03:57:28+00:00

i know how to hard code an algorithm on how to check the types

  • 0

i know how to hard code an algorithm on how to check the types of each object in an arraylist, but is there any other way in checking the type of that ArrayList<> in one go, i mean my application has only three types of arraylist. Say i have a function that returns an ArrayList, and its definiton is that in a variable o (its an arraylist of object ofcourse) i’ll add a person object,

o.add(person);

and having added all person data on an arraylist of objects and when a call this function say the name of my function is getData(),

ArrayList <Object> obj = getData();

so i know that in that ArrayList that i returned from calling getData() that it is all person object, how do i know the type of that ArrayList?.

Just wanted that function to be more generic in sense, this is for my application though, geniric troughout my application.

Is there any other way of doing this, i can think of an algorithm but is there any short cut or easy way of doing this?..

  • 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-11T03:57:29+00:00Added an answer on June 11, 2026 at 3:57 am

    There is no such thing as ‘the type’ of an ArrayList.

    The class ArrayList stores a list of Object references. It doesn’t know and doesn’t care if they are all of some type.

    The Java generic system adds compile-time checking to help you keep track of types. So, if you declare ArrayList<Person>, you will get compile errors if you write code that could insert a non-Person into your list.

    At runtime, the only way to tell what is in an ArrayList to iterate over all the contained items and check them with instanceof.

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

Sidebar

Related Questions

I know this shouldn't be that hard, but I couldn't find the answer on
I know this sucks. Date stuff sucks hard. But: Imagine a date format like
(I know this is a sort of lazy question, but it's oddly hard to
I know the title is a little off, but it's hard to explain the
I know this is probably super easy, but I'm having a hard time wading
Good day. As i know. There is a root element in XML file. But
Does anyone know if there is any existing solution for determining a timezone from
I'm new to Drupal but I've found my way around it pretty easily. There's
Is there a way to remove all empty cells in an ArrayList by just
We have to code in Assembly which is as you may know hard. Or

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.