Here you can find the source of getUniqueNameWithNumbers(Collection
public static String getUniqueNameWithNumbers(Collection<String> names, String baseName)
//package com.java2s; /******************************************************************************* * Copyright ? 2012-2015 eBay Software Foundation * This program is dual licensed under the MIT and Apache 2.0 licenses. * Please see LICENSE for more information. *******************************************************************************/ import java.util.Collection; public class Main { public static String getUniqueNameWithNumbers(Collection<String> names, String baseName) { if (names == null) { return baseName; }// w w w .jav a 2s . co m String name = baseName; int i = 1; while (names.contains(name)) { name = baseName + i; i++; } return name; } }