How To Set The Arraylist Item To Be Add In To Reverse Order? June 11, 2024 Post a Comment In My Application, I am going to store name of all the available tables from my database with this code: public ArrayList showAllTable() { ArrayListSolution 1: There are several ways to do it. The easiest is probably to change your SQL call by adding ORDER BY. Here's something you can try out:To order the items ascending:StringSQL_GET_ALL_TABLES="SELECT name FROM sqlite_master WHERE type='table' ORDER BY name ASC"; CopyOr descending: StringSQL_GET_ALL_TABLES="SELECT name FROM sqlite_master WHERE type='table' ORDER BY name DESC"; CopyAlternative solutionAnother option would be to do it like you're doing it right now, and instead go through the Cursor from the last to the first item. Here's some pseudo code:Baca JugaAndroid - Assign And Retrieve Id's DynamicallySpinner's Onitemselected Callback Called Twice After A Rotation If Non-zero Position Is SelectedAndroid - Assign And Retrieve Id's Dynamicallyif (cursor.moveToLast()) { while (cursor.moveToPrevious()) { // Add the Cursor data to your ArrayList } } CopySolution 2: before return the values just call the method Collections.reverse(tableList); Copysee the full code public ArrayList<Object> showAllTable() { ArrayList tableList = new ArrayList(); String SQL_GET_ALL_TABLES = "SELECT name FROM sqlite_master WHERE type='table'"; Cursor cursor = db.rawQuery(SQL_GET_ALL_TABLES, null); cursor.moveToFirst(); if (!cursor.isAfterLast()) { do { if(cursor.getString(0).equals("android_metadata")) { //System.out.println("Get Metadata");continue; } else { tableList.add(cursor.getString(0)); } } while (cursor.moveToNext()); } cursor.close(); Collections.reverse(tableList); return tableList; } Copy Share You may like these postsHow To Update Widget Every MinuteAndroid Widget Update After X TimeHow To Hide Or Disable Minutes Widget In Android Timepickerdialog?Showing Terms And Conditions For First Time In An Android App Post a Comment for "How To Set The Arraylist Item To Be Add In To Reverse Order?"