I have a ArrayList<CustomObject> myFinalList = new ArrayList<CustomObject>();
The list has a ojbect property "NumberOfLikes" for each entry in the list. "NumberOfLikes" are String values.
I have derived these values into an array like so:-
ArrayList<String> numberOfLikes = new ArrayList<String>();
for(int j =0; j<myFinalList.size(); j++)
{
String likes = myFinalList.get(j).getNewsLikes();
numberOfLikes.add(likes);
}
numberofLikesArray= numberOfLikes.toArray(new String[numberOfLikes.size()]);
int[] numberofLikesArrayInt = new int[numberofLikesArray.length];
for (int n = 0; n < numberofLikesArray.length; n++)
{
numberofLikesArrayInt[n] = Integer.parseInt(numberofLikesArray[n]);
}
Arrays.sort(numberofLikesArrayInt);
ArrayList<Integer> intAarrylistlikes = new ArrayList<Integer>();
for (int i = 0; i < numberofLikesArrayInt.length; i++)
{
intAarrylistlikes.add(numberofLikesArrayInt[i]);
}
Collections.reverse(intAarrylistlikes);
numberofLikesArrayInt = convertIntegers(intAarrylistlikes);
numberofLikesArray = Arrays.toString(numberofLikesArrayInt).split("[\\[\\]]")[1].split(", ");
for (int i = 0; i < numberofLikesArray.length; i++)
{
companyNewsList = Lists.newArrayList(Collections2.filter(myFinalList, new ArticleFilter2(numberofLikesArray[i])));
}
ArticleFilter2.java
public class ArticleFilter2 implements Predicate<News>
{
private final Pattern pattern;
public ArticleFilter2(final String regex)
{
pattern = Pattern.compile(regex);
}
@Override
public boolean apply(final CustomObject input)
{
return pattern.matcher(input.getLikes()).find();
}
}
Now this array consists of the "NumberOfLikes" in descending order. Now I want to create another ArrayList which sorts the "MyFinalList" according to these values ie:- item having the maximum likes should appear first.
How can I do it?