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

  • Home
  • SEARCH
  • 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 8380113
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T16:22:28+00:00 2026-06-09T16:22:28+00:00

I have numbers in an array list which also contains alphanumeric. For example. 1

  • 0

I have numbers in an array list which also contains alphanumeric. For example.

1          1a
2          1b
3          2
4a         3
4b         4
4c         5a
4d   (or)  5b   (or) [in any sequence may be]
5          5c
6          6
7          7
8          8 
9a         9
9b         10
10      

I this how to delete a single element and reorder the whole list. For example from above list I am going to delete 2, then the result must be.

1          1a
           1b
2           
3a         2
3b         3
3c         4a
3d   (or)  4b   (or) [in any sequence may be]
4          4c
5          5
6          6
7          7
8a         8
8b         9
9      

I this how to delete a single element and reorder the whole list. For example from above list I am going to delete 3a in left side list and 1b(or)1a in the other hand, then the result must be.

           1
1          
2           
           2
3a         3
3b         4a
3c   (or)  4b   (or) [in any sequence may be]
4          4c
5          5
6          6
7          7
8a         8
8b         9
9      

I hope this will explain that what I needed. How to achieve this????

  • 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-06-09T16:22:29+00:00Added an answer on June 9, 2026 at 4:22 pm

    In this you can change the values of string idString and itemToDelete what ever you like to change. It will give the desired output.

    import java.util.ArrayList;
    import java.util.List;
    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
    
    
    public class OrderTheListBasedOnItemDeleted {
    
    
        public static void main(String[] args) {
    
            List<String> idList = new ArrayList<String>();
            String idToBeDeleted="5a";
    
            String idString= "1,2a,2b,2c,3,4,5a,5b";
    
            String idArray[]=idString.split(",");
    
            for(int i=0;i<idArray.length;i++){
                idList.add(idArray[i]); 
            }
    
    
            int duplicateCount=0;
             List<Integer>indexOfItemsForReorder = new ArrayList<Integer>();
    
                Pattern patternDigit = Pattern.compile("\\d+",Pattern.CASE_INSENSITIVE);
                Pattern patternLetter = Pattern.compile("[a-zA-Z]+",Pattern.CASE_INSENSITIVE);
                String digit="";
                String letter="";
                String digit2="";
                String letter2="";
    
    
            for(String a :idList){
                System.out.println(a);
            }
            System.out.println();
    
    
            Matcher mD = patternDigit.matcher(idToBeDeleted);
            Matcher mL = patternLetter.matcher(idToBeDeleted);
            if (mD.find()) {
                digit  = mD.group();
            }
            if (mL.find()) {
                letter  = mL.group();
            }
    
    
            if(letter!=""){
                    for(String idToBeDeleted : idList){
    
                                Pattern patternDigitLetter = Pattern.compile(digit+"[a-zA-Z]+",Pattern.CASE_INSENSITIVE);   
                                Matcher digitletterMatcher = patternDigitLetter.matcher(idToBeDeleted);
                                if(digitletterMatcher.find()){
                                    indexOfItemsForReorder.add(idList.indexOf(digitletterMatcher.group()));
                                    duplicateCount=duplicateCount+1;
                                }
                    }
                    int indexofContentToBeReplaced = indexOfItemsForReorder.get(indexOfItemsForReorder.size()-1);
                    //for letter more than 2...
                    if(duplicateCount>2){
                        idList.remove(indexofContentToBeReplaced);
                    }else if(duplicateCount>=1&&duplicateCount<=2){
                        //for letter more than 1 and less than 2...
    
                        idList.remove(indexofContentToBeReplaced);
                        idList.remove(indexofContentToBeReplaced-1);
                        idList.add(indexofContentToBeReplaced-1, digit);
    
    
                    }
    
    
                    System.out.println("result...");
    
        }else{
                int indexOfItemToBeDeleted=idList.indexOf(idToBeDeleted);       
                List <String> newIdList = new ArrayList<String>();
    
                for(int i=0;i<indexOfItemToBeDeleted ;i++){
    
                    newIdList.add(idList.get(i));
                }
                idList.remove(idToBeDeleted);
    
                for(int i=indexOfItemToBeDeleted; i<idList.size(); i++){
                    digit2="";
                    letter2="";
                    Matcher mD2 = patternDigit.matcher(idList.get(i));
                    Matcher mL2 = patternLetter.matcher(idList.get(i));
                    if(mD2.find()){
                        digit2=mD2.group();
                    }
    
                    if (mL2.find()) {
                        letter2  = mL2.group();
                    }
    
                    int d=Integer.parseInt(digit2);
                    d=d-1;
                    newIdList.add(i, Integer.toString(d)+letter2);
    
                }
    
                if(newIdList.contains("0")){
                    newIdList.remove("0");
                }
    
    
                System.out.println("result...");
                idList.clear();
                idList=newIdList;
        }
    
            for(String a :idList){
                System.out.println(a);
            }
    
    
        }
    }
    

    OUTPUT

    Input
    1
    2a
    2b
    2c
    3
    4
    5a
    5b
    
    result...
    1
    2a
    2b
    2c
    3
    4
    5
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array which contains 12 numbers and I want to save this
I have this string of numbers var array = 1,6,2,9,5 which is retrieved from
Hi I have an array list which has some numbers in it like {23,16,45,26,2,5,9}
I have an NSMutableArray which contains a list of numbers taken from a textfield.
I have an array called $times . It is a list of small numbers
Lets say I have an array numbers that contains the following values: int numbers
I have a text file containing a giant list of line numbers which I
I have this method to display the contact numbers in my inbox: public ArrayList<String>
I have an array of numbers: @numbers = 1,2,3,6,8,9,11,12,13,14,15,20 and I want to print
I have a PHP array with numbers of ID's in it. These numbers are

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.