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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T22:17:46+00:00 2026-06-04T22:17:46+00:00

I am facing a problem in sorting. The format of data is: b4 S0_c5

  • 0

I am facing a problem in sorting. The format of data is:

b4 S0_c5 t 0.426544 
b6 S1_c5 t 1.51049 
b13 S0_c5 t 0.594502 
b13 S1_c5 t 0.537496 
b15 S1_c5 t 0.884126   
b18 S0_c5 t 0.500933 
b19 S1_c5 t 0.628472 
b22 S0_c5 t 0.437718 

and required result is:

S0_c5 b13 0.594502 b18 0.500933 b22 0.437718 b4 0.426544 
S1_c5 b6 1.51049 b15 0.884126 b19 0.628472 b13 0.537496 

the value is also in descending order. Thanks in advance.

  • 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-04T22:17:48+00:00Added an answer on June 4, 2026 at 10:17 pm

    Put the data in a TreeList<String, List<String>> (because it’s sorted) where the second word from a sequence is the key, and the value a list of strings, then sort each list you obtain this way:

        Map<String, List<String[]>> map = new TreeMap<String, List<String[]>>();
        for (String s : strings) {
            String[] tokens = s.split(" ");
            List<String[]> values = map.get(tokens[1]);
            if (values == null) {
                values = new ArrayList<String[]>();
                map.put(tokens[1], values);
            }
            values.add(new String[]{tokens[0],  tokens[3]});
        }
    
        for (String key : map.keySet()) {
            List<String[]> list = map.get(key);
            Collections.sort(list, new Comparator<String[]>() {
    
                @Override
                public int compare(String[] o1, String[] o2) {
                    return o1[1].compareTo(o2[1]) * -1;
                }
    
            });
    
            System.out.print(key + " ");
            for (String[] s : list) {
                System.out.print(s[0] + " " + s[1]);
            }
            System.out.println();
        }
    

    Update:
    E.g. to read from a file:

        BufferedReader br;
        try {
            br = new BufferedReader(new FileReader("d:/temp/r.res"));
    
            Map<String, List<String[]>> map = new TreeMap<String, List<String[]>>();
            while (br.ready()) {
                String s = br.readLine();
                if (!s.trim().isEmpty()) {
                    String[] tokens = s.split(" ");
                    List<String[]> values = map.get(tokens[1]);
                    if (values == null) {
                        values = new ArrayList<String[]>();
                        map.put(tokens[1], values);
                    }
                    values.add(new String[]{tokens[0],  tokens[3]});
                }
            }
        } finally {
            br.close();
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im facing problem when trying to apply data annotation. In my case im passing
I am facing problem in getting Facebook data I am using Facebook SDK for
I have facing problem in listview i am getting data from server and after
I am facing a strange problem while sorting a list of strings with integer
I m facing problem in sorting this 2-d array on the basis of key
I am facing problem with lastButton of SimplePager. I have 3 pages in celltable,
I am facing problem in showing the preview of first letter in Android listview,
I am facing problem with the control flajaxian.FileUploader i.e. after downloading the dll file
i am facing problem with ipv6 validations and ipv4 validations in JavaScript please help
I am facing problem while generating CAB file. I want to customize the INF

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.