Mehul Akoliya
Mehul Akoliya

Reputation: 286

Sort Arraylist in Android

I'm trying to sort an ArrayList in my Android app, but its throwing an exception. Here's the part of my code where it happens:

List<PackageInfo> packs = getPackageManager().getInstalledPackages(0);  
Collections.sort(packs);

Does anybody have any ideas?

Upvotes: 5

Views: 4538

Answers (3)

Niranj Patel
Niranj Patel

Reputation: 33248

here is a simple example of How to sort array in android?.

String[] array = new String[]{"one","two","three","four"};
Arrays.sort(array);

Upvotes: 2

MrJre
MrJre

Reputation: 7161

packs contains PackageInfo objects, and sort can not find a natural order for those is my best guess. If you want to sort, use a Comparator with the sort which defines what you want to sort the PackageInfo objects on.

Upvotes: 3

Android
Android

Reputation: 9023

sorting
another example
one more
this also
may above link helpful to you Happy Coding..:):) thanks Pragna

Upvotes: 2

Related Questions