I have;
List stringList = new ArrayList(); List integerList = new ArrayList();
Is
Had the same problem, but I used instanceof instead. Did it this way:
List listCheck = (List)(Object) stringList; if (!listCheck.isEmpty()) { if (listCheck.get(0) instanceof String) { System.out.println("List type is String"); } if (listCheck.get(0) instanceof Integer) { System.out.println("List type is Integer"); } } }
This involves using unchecked casts so only do this when you know it is a list, and what type it can be.