1. 程式人生 > >Java 字串List轉int List

Java 字串List轉int List

String menuIds = "1,2,3,4,5,6";
List<String> inputMenuIds = Arrays.asList(menuIds.split(","));
List<Integer> menuIdList = new ArrayList<Integer>();
CollectionUtils.collect(inputMenuIds, new Transformer() {
   @Override
public Object transform(Object o) {
      return Integer.valueOf
(o.toString()); } }, menuIdList);
用到的包 
org.apache.commons.collections.CollectionUtils;