Java tutorial
//package com.java2s; import java.util.ArrayList; public class Main { public static ArrayList<Integer> getArrayList(String aggregate) { if (aggregate.equals("")) return null; ArrayList<Integer> list = new ArrayList<Integer>(); String[] tokens = aggregate.split(","); for (String t : tokens) { if (t.contains("-")) { String[] indices = t.split("-"); for (int i = Integer.parseInt(indices[0]); i <= Integer.parseInt(indices[1]); i++) list.add(i); } else { list.add(Integer.parseInt(t)); } } return list; } }