Java Map Remove removeTrailingNumber(Map names)

Here you can find the source of removeTrailingNumber(Map names)

Description

remove Trailing Number

License

Open Source License

Declaration

public static void removeTrailingNumber(Map names) 

Method Source Code

//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));
            }
        }
    }
}

Related

  1. removeOutStringsStrings(Map map, String newString)
  2. removeParamsForAlipaySign(Map map)
  3. removeParentBeans(Map parentBeans, Map beans)
  4. removePrivateColumns( Map contentValues)
  5. removeRownum(List> rows)
  6. removeValue(final Map map, final Object key, final Object value)
  7. removeValue(Map subject, String property, Map value, boolean propertyIsArray)
  8. removeValueFromAll(final Map map, final Object value)
  9. removeValueList(final Map> map, final K key, final V value)