sort string by length

Hi Everyone

I have a set of data

qqq

adadada as

aas a

asada

adasdas adada

now I need a formula which can sort these strings according to the length. So the longest string will come at the top. I would really appreciate if anyone could help me with it.

Thanks

[313 byte] By [sifatkhana] at [2007-11-27 5:03:23]
# 1

If you need to code this yourself then simply implement a sorting algorithm, get the two lengths and swap the Strings if necessary.

If you can utilise the sort method written in Collections class, then you will need to write your own Comparator.

Read about these classes and try it yourself. If you are still having trouble come back and ask a specific question.

floundera at 2007-7-12 10:21:27 > top of Java-index,Java Essentials,Java Programming...