Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6677075
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:04:20+00:00 2026-05-26T04:04:20+00:00

I have list of String. List<String> elements= new ArrayList<String>(); when I wanna add new

  • 0

I have list of String.
List<String> elements= new ArrayList<String>();
when I wanna add new String

elements.add(“element”);

with name which is my arraylist I wanna to automatically rename to _[a-z…] as windows rename file when there are two same… so for example I have in arraylist “element” when I add element again I wanna to rename automatically to element_a … so

    if (elements.contains("element")) { 
    something
}

is there some function in java ?
thx for help

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T04:04:21+00:00Added an answer on May 26, 2026 at 4:04 am

    No built-in function, but it’s not too hard. For example:

    public static void main(String[] args) {
        List<String> l = new ArrayList<String>();
        add("foo", l);
        add("foo", l);
        add("foo", l);
        add("foo", l);
        add("foo", l);
        add("foo", l);
        add("foo", l);
        add("foo", l);
        System.out.println(l);
    }
    
    static void add(String element, List<String> elements) {
        if (elements.contains(element)) {
            elements.add(nextValudFor(element, elements));
        } else {
            elements.add(element);
        }
    }
    
    static String nextValudFor(String element, List<String> elements) {
        for (char c = 'a'; c <= 'z'; c++) {
            String next = element + '_' + c;
            if (!elements.contains(next)) {
                return next;
            }
        }
        throw new IllegalStateException("Ran out of letters!");
    }
    

    Outputs:

    [foo, foo_a, foo_b, foo_c, foo_d, foo_e, foo_f, foo_g]
    

    For best effect, you’d probably want to wrap this up into your own List type as appropriate.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a List with the following elements. List<String> numbers = new ArrayList<String>(); numbers.add(1);
I have a doubt considering changing this : List<String> elements = new ArrayList<String>(); elements
I have a list like this Dim emailList as new List(Of String) emailList.Add(one@domain.com) emailList.Add(two@domain.com)
I have String arrays of arrays. List<String[]> mainList = new ArrayList<String[]>(); String[] row1 =
I have a list of string values that I want add to a hashtable
I have the following code: // Form the continuities list string[] continuities = new
Hey, I have this code here: ArrayList arrayList = new ArrayList(); arrayList.add(one); arrayList.add(two); arrayList.add(three);
I have declared an ArrayList and DefaultListModel DefaultListModel model; List<AddFlight> Flights = new ArrayList<AddFlight>();
I'm new to python, and have a list of longs which I want to
public List<Afood> getFoodFromCat(String cat) { String resultado = ; List<Afood> list = new ArrayList<Afood>();

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.