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 8783513
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:50:42+00:00 2026-06-13T20:50:42+00:00

I am studying JAVA and I have a question about Sorting string. In the

  • 0

I am studying JAVA and I have a question about Sorting string.

In the String ArrayList
We have string value STRUCTURE is “0” + ” ” + “some string”

for example,

     | String
     | 0 AA
     | 1 BB
     | 2 AA
     | 3 AA
     | 4 CC
     | 5 BB

and

when we sort it, result should be

     | String 
     | 0 AA
     | 2 AA
     | 3 AA
     | 1 BB
     | 5 BB
     | 4 CC

how can I sort the String with “number string” + ” ” + ” String”

thanks

update:

i tested code blow with
1 AA
2 AA
3 BBB
4 CC
5 BBB
6 AA
7 BBB
8 CC
9 ZZZ
10 QQQ

and I got

0 AA

1 AA

5 AA

4 BBB

2 BBB

6 BBB

3 CC

7 CC

9 QQQ

8 ZZZ

  • 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-13T20:50:43+00:00Added an answer on June 13, 2026 at 8:50 pm

    I dint really consider space and time complexity while coding it. i am not really sureits efficient enough, but it would give you anidea.

      List<String> l = new ArrayList<>();
    
            l.add("0 CC");
            l.add("1 BB");
            l.add("2 AA");
            l.add("3 AA");
    
        String str="";
        for(String s: l){
            str+=s+",";
        }
        String[] sArr = str.split(",");
        String temp="";
        for(int i=0; i<sArr.length;i++) {
            for(int j= i+1; j<sArr.length;j++){
                if(sArr[i].split("\\s")[1].compareToIgnoreCase(sArr[j].split("\\s")[1])>0){
                    temp= sArr[j];
                    sArr[j]= sArr[i];
                    sArr[i]=temp;
                }
            }
        }
        for(String g: sArr){
            System.out.println(g);
        }
    
    output:
    2 AA
    3 AA
    1 BB
    0 CC
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am studying Java and sorting. I have a question about tracking the index
I am studying Java concurrency right now. I have a question about synchronized and
I have some question about arrays, I'm reading some book about Java, and now
While studying Java tutorials, Reflection and Late Binding have confused me. In some tutorials,
I began studying Java Regular Expression recently and I found some really intersting task.For
I was studying about polymorphism. I couldn't determine the analogy in Java about these
Total noobie question here. I'm just learning Java, and studying passing arguments to functions.
I am studying for a final and have a few questions about RMI and
I'm a .net developer and I am studying Swing for Java and I have
I'm new to Objective-C world. What I have noticed while studying some iOS/Mac apps

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.