0

I have two Strings s1 and s2 which has amount in that String, I need to sort the whole String based on amount adnd store in arralist.In below code s1 has amount 1541.81 and s2 has amount 500.55, based on amount sort the string and store in Arraylist.

String s1="TO210727B3 1541.81 BBN892400                         S103";
String s2="TI210727T6 500.55 BBN793700                TDOMCATTTS205";
Output ArrayList l=[TI210727T6 500.55 BBN793700 TDOMCATTTS205,TO210727B3 1541.81 BBN892400  S103]
Braiam
  • 1
  • 11
  • 47
  • 78
arun
  • 25
  • 5

1 Answers1

0

You first need to extract the data from the String. In your case it looks like that can be done with

double valueOfS1 = Double.parseDouble(s1.split(" ")[1]);
// likewise for s2

And then sort using those values. Sorting can be done with a TreeSet that you insert all the values into and then converting that to an array.

0xff
  • 181
  • 2
  • 11