Here you can find the source of removeTrailingNumber(Map names)
public static void removeTrailingNumber(Map names)
//package com.java2s; import java.util.Iterator; import java.util.Map; public class Main { public static void removeTrailingNumber(Map names) { boolean same = true; String lastChar = null;//from w w w . j ava 2 s. c o m Iterator it = names.keySet().iterator(); while (it.hasNext()) { String key = (String) it.next(); String value = (String) names.get(key); if (lastChar == null) { lastChar = value.substring(value.length() - 1, value.length()); } else if (!value.endsWith(lastChar)) { same = false; break; } } if (same) { // remove last char everywhere and do recursive call it = names.keySet().iterator(); while (it.hasNext()) { String key = (String) it.next(); String value = (String) names.get(key); names.put(key, value.substring(0, value.length() - 1)); } } } }