I donβt think there is an automatic way to do this, simply because of how Java compiles common arguments (called type erasure, a difficult way to say βHaha, we actually only save object references and the compiler inserts the cast into the general argument each time you do get () ").
Why should you convert it to a list of strings? Isn't it the same when you need a list of strings to just iterate over a list of integers and call toString () on each of them?
EDIT:
anyway, here is a solution that will work:
public static List<String> convToString(List<Integer> list){ List<String> ret = new ArrayList<String>(); for (Integer i : list){ ret.add(i.toString()); } return ret; }
And again!
public static List<Integer> convToInteger(List<String> list){ List<Integer> ret = new ArrayList<Integer>(); for (String s : list){ ret.add(Integer.parseInt(s)); } return ret; }
source share