I have the below function:
public void putList(String key, List lst){
if (T instanceof String) {
// Do something
Generics are called "erasures" because they exist at compile time only and are removed by compiler. So, there is no way to determine the generic type of collection. The only way to do it for non-empty lists is to take the first element and determine its type.
This is almost the same solution that was suggested by DJClayworth, but I think that there is no need to check each element of the list. If you are sure that the list is created with generics (new ArrayList() or new LinkedList() etc) all its element are guaranteed to be of the same type.