Java tutorial
//package com.java2s; /** * Copyright (c) 2011 Loganalysis team and contributors * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * Raffael Schmid - initial API and implementation */ import java.math.BigDecimal; import java.util.ArrayList; import java.util.Collections; import java.util.List; public class Main { public static List<BigDecimal> intervals(final List<BigDecimal> list) { // list must be sorted for interval calculation Collections.sort(list); final List<BigDecimal> retVal = new ArrayList<BigDecimal>(); BigDecimal before = list.get(0); for (int i = 1; i < list.size(); i++) { final BigDecimal current = list.get(i); retVal.add(current.subtract(before)); before = current; } return retVal; } }