Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


Dhruv Gupta
Dhruv Gupta
4,320 Points

Removing a pointer to a parse user from an array

have a parseobject which consists of many objects, notably an array of consisting of ParseUser pointers.

When an individual clicks a button, the array should remove a certain user. I don't get how to do this,

I have tried: mRideEdit.removeAll("Participant", (Collection) childuser);

Where mRideEdit is my ParseClass, Participant is the array consisting of ParseUsers, and childuser is the user I want to remove

Please help,

1 Answer

Harry James
Harry James
14,780 Points

Hey Dhruv!

I've managed to use this code to remove an object from an array - this works for a String and you would have to change it around a bit for your array of ParseUser's (If you need help with that, let me know):

        String[] arrayOfStrings = {"User1", "User2", "User3"};
        List<String> listOfStrings = new ArrayList<String>(Arrays.asList(arrayOfStrings));
        String[] updatedArrayOfStrings = listOfStrings.toArray(new String[(arrayOfStrings.length-1)]);

Here is the same version but with comments explaining it all:

String[] arrayOfStrings = {"User1", "User2", "User3"};
// Here, we have our array with all of the users in.

List<String> listOfStrings = new ArrayList<String>(Arrays.asList(arrayOfStrings));
// We're going to create a list by converting our array into a list.

/* Now that we've converted to a list, we can remove from the list anywhere that we see "User1" -
if you want to remove more than one user, you would use removeAll(Arrays.asList("User1", "User2")). */

String[] updatedArrayOfStrings = listOfStrings.toArray(new String[listOfStrings.size()]);
/* Now, let's create the array again (Remember - we have to create a new array as we can't change
array sizes on the fly, they keep their size after they've been initialized). */
/* We'll create this array so it's the same size as our list (Remember, the list has already had the
users removed so it is of the correct size). */
/* This method will work whether you are removing 1 or more users - there's no need to change anything. */

Hopefully I've explained how you can do this for ParseUser's (The code is the same - you just need to change the object to a ParseUser instead of a String) but if not, let me know and I'll try to help you out :)