Here you can find the source of concatIntegersToRanges( List
public static ArrayList<int[]> concatIntegersToRanges( List<Integer> damages)
//package com.java2s; //License from project: LGPL import java.util.*; public class Main { public static ArrayList<int[]> concatIntegersToRanges( List<Integer> damages) { ArrayList<int[]> ranges = new ArrayList<int[]>(); if (damages.size() == 0) return ranges; Collections.sort(damages); int start = -1; int next = 0; for (Integer i : damages) { if (start == -1) { start = next = i;//from w w w. j av a2s. c om continue; } if (next + 1 != i) { ranges.add(new int[] { start, next }); start = next = i; continue; } next = i; } ranges.add(new int[] { start, next }); return ranges; } }