String sorting

D

DBC User

Hi I am newbie to Java. I am using an arraylist to collect string line
input from gui. So my array list is list of strings. I want to sort it.
What is the best way to sort this in ascending order?
Thanks
 
D

DBC User

Thanks both Arrays.sort is what I was looking for. But I still have an
issue with the order in which it sorts.

I have following input

Aa bB Cc
aa bb cc
Aa Bb Cc
Aa bb Cc
Aa bb cc
bb cc aa

and I get the following output

aa bb cc
bb cc aa
Aa bb cc
Aa bb Cc
Aa bB Cc
Aa Bb Cc

But I would like to get
aa bb cc and then
Aa bb Cc

Is there a way to do this in the sort?
'Thanks.
 
P

Patricia Shanahan

DBC said:
Thanks both Arrays.sort is what I was looking for. But I still have an
issue with the order in which it sorts.

I have following input

Aa bB Cc
aa bb cc
Aa Bb Cc
Aa bb Cc
Aa bb cc
bb cc aa

and I get the following output

aa bb cc
bb cc aa
Aa bb cc
Aa bb Cc
Aa bB Cc
Aa Bb Cc

But I would like to get
aa bb cc and then
Aa bb Cc

Is there a way to do this in the sort?

Supply a Comparator that implements the ordering you want.

Patricia
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
474,266
Messages
2,571,083
Members
48,773
Latest member
Kaybee

Latest Threads

Top