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]

1
  • apply bubble sort algorithm and print in reverse order. Commented Apr 28, 2015 at 5:32

2 Answers 2

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 ;)

Sign up to request clarification or add additional context in comments.

4 Comments

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]
@user3790247 this happens when you use string array, please confirm
yes im sorting the string array , if i changed to integer means works perfect thanks all
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 :)
0

One Suggestion :

your_array.sort(function(a, b){return b-a});

1 Comment

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 :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.