直接贴代码
import java.util.ArrayList;
public class Test {
public static void main(String[] args) {
ArrayList<Integer> brandIdArrayList = new ArrayList<Integer>();
brandIdArrayList.add(12);
brandIdArrayList.add(15);
brandIdArrayList.add(18);
ArrayList<Long> brandIDs = new ArrayList<Long>();
for (int i = 0; i < brandIdArrayList.size(); i++) {
brandIDs.add(Long.parseLong(String.valueOf(brandIdArrayList.get(i))));
}
System.out.println(brandIDs);
}
}
java中int转为long,需要先用String.valueof()转为string,然后再Long.parseLong()转为long类型。