Java tutorial
//package com.java2s; import java.util.ArrayList; import java.util.List; public class Main { public static List<Integer> range(int from, int to) { List<Integer> result = new ArrayList<Integer>(Math.max(from, to) - Math.min(from, to) + 1); if (to > from) { for (int i = from; i <= to; i++) result.add(i); } else { for (int i = from; i >= to; i--) result.add(i); } return result; } }