0

I want to sort the array list with having maximum value in first position. Currently I am doing as shown below:

for (int i = 0; i < str_position.size(); i++) { 

                            int position_id = str_position_id_one_time;
                            position_id--;
                            Log.e("position_id---=------>",""+position_id);
                            str_position_id_one_time = position_id; 
                            array_bitmap_grid_adpater.remove(Integer.parseInt(str_position.get(i)));
                            adapter_GridView.notifyDataSetChanged();

Sort the array list maximum value on first position ex : [0, 1, 5, 3] i need [5, 3, 1, 0]

keshav kowshik
  • 2,354
  • 4
  • 22
  • 45
Prithiviraj
  • 31
  • 1
  • 11

2 Answers2

1

Here's one way for your list:

Collections.sort(list);
Collections.reverse(list);

OR this one line

Collections.sort(unsortedArrayList, Collections.reverseOrder());

First sort it then reverse it ;)

Salmaan
  • 3,543
  • 8
  • 33
  • 59
  • its not sorting if the array count more that 10 ex : [4, 6, 7, 9, 10, 11, 8, 5, 2, 1] this is sorted array [9, 8, 7, 6, 5, 4, 2, 11, 10, 1] – Prithiviraj May 08 '15 at 07:43
  • @user3790247 this happens when you use string array, please confirm – Salmaan May 08 '15 at 09:43
  • yes im sorting the string array , if i changed to integer means works perfect thanks all – Prithiviraj May 08 '15 at 11:15
  • Yes it works great if you're using int array :) Please up-vote and mark as correct so we can help others to find correct solution :) – Salmaan May 08 '15 at 11:24
0

One Suggestion :

your_array.sort(function(a, b){return b-a});
NickOS
  • 764
  • 1
  • 7
  • 18
  • 1
    Generally, answers are much more helpful if they include an explanation of what the code is intended to do, and why that solves the problem without introducing others :) – Jaime Gómez Apr 28 '15 at 06:03