Skip to content

Displaying some query records in random order (

Okay so the following is my ParseQuery. How can I display most but not all of the records in random order using Collections.shuffle() in this context? For example, I have a specific record that I want always to display at the top of the list but I want everything other than that specific record to be displayed in random order beneath it.

I’d prefer not to set up two different ArrayLists, displaying the one specific record in one and the rest in the other, but that is always an option.

Can I do something like removing the specific record from the shuffle based on its objectId somehow?

brandlist = new ArrayList<SuggestedBrand>();
        try {
            // Locate the class table named "SuggestedUser" in
            ParseQuery<ParseObject> query = new ParseQuery<ParseObject>(

            ob = query.find();
            for (ParseObject author : ob) {
                ParseFile image = (ParseFile) author.get("brandImage");
                SuggestedBrand map = new SuggestedBrand();
                map.setRank((String) author.get("author"));
                map.setUsername((String) author.get("username"));
                map.setUserID((String) author.get("userId"));
        } catch (ParseException e) {
            Log.e("Error", e.getMessage());
        return null;



Why don’t you just remove the one interesting item (and store it in a variable) just before using Collections.shuffle(...), and after using the method insert the item back into the ArrayList at the top of it?

User contributions licensed under: CC BY-SA
4 People found this is helpful