Here you can find the source of sumCreditList(List
public static String sumCreditList(List<String> list)
//package com.java2s; import java.util.*; public class Main { /**/*from w ww . j a v a2s.c o m*/ * Creates the sum of a list of credit ranges, returning the cumulative min and max credits * eg "1-2", "3-5" would return "4-7" */ public static String sumCreditList(List<String> list) { if (list == null || list.isEmpty()) return "0"; float minCredits = 0; float maxCredits = 0; for (String item : list) { String[] split = item.split("[ ,/-]"); String first = split[0]; float min = Float.parseFloat(first); minCredits += min; String last = split[split.length - 1]; float max = Float.parseFloat(last); maxCredits += max; } String credits = Float.toString(minCredits); if (minCredits != maxCredits) { credits = credits + "-" + Float.toString(maxCredits); } credits = credits.replace(".0", ""); return credits; } }