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

  • Home
  • SEARCH
  • 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 507657
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:49:37+00:00 2026-05-13T06:49:37+00:00

I have; List<String> stringList = new ArrayList<String>(); List<Integer> integerList = new ArrayList<Integer>(); Is there

  • 0

I have;

List<String> stringList = new ArrayList<String>();
List<Integer> integerList = new ArrayList<Integer>();

Is there a (easy) way to retrieve the generic type of the list?

  • 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-13T06:49:37+00:00Added an answer on May 13, 2026 at 6:49 am

    If those are actually fields of a certain class, then you can get them with a little help of reflection:

    package com.stackoverflow.q1942644;
    
    import java.lang.reflect.Field;
    import java.lang.reflect.ParameterizedType;
    import java.util.ArrayList;
    import java.util.List;
    
    public class Test {
    
        List<String> stringList = new ArrayList<>();
        List<Integer> integerList = new ArrayList<>();
    
        public static void main(String... args) throws Exception {
            Class<Test> testClass = Test.class;
    
            Field stringListField = testClass.getDeclaredField("stringList");
            ParameterizedType stringListType = (ParameterizedType) stringListField.getGenericType();
            Class<?> stringListClass = (Class<?>) stringListType.getActualTypeArguments()[0];
            System.out.println(stringListClass); // class java.lang.String
    
            Field integerListField = testClass.getDeclaredField("integerList");
            ParameterizedType integerListType = (ParameterizedType) integerListField.getGenericType();
            Class<?> integerListClass = (Class<?>) integerListType.getActualTypeArguments()[0];
            System.out.println(integerListClass); // class java.lang.Integer
        }
    
    }
    

    You can also do that for parameter types and return type of methods.

    But if they’re inside the same scope of the class/method where you need to know about them, then there’s no point of knowing them, because you already have declared them yourself.

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

Sidebar

Related Questions

If I have a simple list of Strings: List<String> stringList = new ArrayList<String>(); I
I have a String list: List<String> listString = new ArrayList<String>(); listString.add(faq); listString.add(general); listString.add(contact); I
I have a String list ArrayList<String> list = new ArrayList<String>(); with each item: list.add(week+
I have a list like this Dim emailList as new List(Of String) emailList.Add(one@domain.com) emailList.Add(two@domain.com)
I have a class like this public SomeClass { private List<string> _strings = new
How would I convert List list= new ArrayList(); to String [] profArr= {}; I
I have a jagged array that looks like this: string[][] list = new string[d.Rows.Count
I have a String List with items like this Root Root/Item1 Root/Item2 Root/Item3/SubItem1 Root/Item3/SubItem2
I have a string list (TStrings) that has a couple thousand items in it.
I have List[(String,String)] and I need to sort them by the 2nd value and

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.