Here you can find the source of renameDuplicateStrings(List
public static List<String> renameDuplicateStrings(List<String> strNames)
//package com.java2s; //License from project: Open Source License import java.util.ArrayList; import java.util.HashMap; import java.util.List; public class Main { public static List<String> renameDuplicateStrings(List<String> strNames) { if (strNames == null) { return null; }/*from w ww .j a v a 2 s . c om*/ HashMap<String, Integer> seenBefore = new HashMap<String, Integer>(4); List<String> results = new ArrayList<String>(strNames.size()); for (String str : strNames) { Integer lookup = seenBefore.get(str); if (lookup == null) { results.add(str); seenBefore.put(str, 1); } else { results.add(str + "_" + lookup); seenBefore.put(str, lookup + 1); } } return results; } }