I have an arraylist and I want to use arrays.sort to sort them alphabetically, but when I run the app, the list is totally not sorted. I am not sure what’s wrong.
public class AList extends ListActivity {
static String[] People = new String[] {
"John Ken",
"Albert Chan",
"Kelvin McDonald"};
public static void main(String[] args) {
Arrays.sort(People);}
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.activity_alist);
setListAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1,
People));
I don’t think your
mainmethod executes (Android has its ownmainmethod).Try calling
Arrays.sort()in youronCreatemethod instead.