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