Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
233 views
in Technique[技术] by (71.8m points)

java - how to sort an ArrayList in ascending order using Collections and Comparator

How to sort an ArrayList in ascending order using Comparator? I know how to sort it in descending order using:

Comparator mycomparator = Collections.reverseOrder();

then

Collections.sort(myarrayList,mycomparator);

just want to know how to sort it in ascending order using Collections and comparator? Thanks!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Just throwing this out there...Can't you just do:

Collections.sort(myarrayList);

It's been awhile though...


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...