# 7.10 Remove Group Members Except List

The `removeMembersExceptList` method is used to remove all members of the Group except the list of group members. Calling member is not removed from the group. Any existing member of the group can remove other members. The developer can choose to build stricter access-control mechanisms on top of this if desired (e.g. only the group-owner or group-admin is authorized to remove members from the group).

The function takes the following parameters :

* **groupId**  :  GroupId of the group.
* **groupMembers** : `List<GroupMember>` of `GroupMember` **NOT** to be removed from the group. If the list is empty, all the members of the group are  removed except the calling member.
* **removeCallingMember :** Determines whether the calling member should be removed from the group or not.
* **success** : Success block to be executed after group is successfully joined.
* **failure** : Failure block to be executed if group could not be joined, returns `BayunError`.

{% tabs %}
{% tab title="Java" %}

```java
import com.bayun_module.GroupMember

String companyEmployeeId = "<companyEmployeeId>";
String companyName = "<companyName>";
String groupId = "<groupId>";
boolean removeCallingMember = <removeCallingMember>;

GroupMember groupMember = new GroupMember();
groupMember.companyEmployeeId = companyEmployeeId;
groupMember.companyName = companyName;
            
ArrayList<GroupMember> groupMembers = new ArrayList<>();
groupMembers.add(groupMember); 

//Success Callback
Handler.Callback success = new Handler.Callback() {
    @Override
    public boolean handleMessage(Message message) {
        return false;
    }
}
//Failure Callback
Handler.Callback failure = new Handler.Callback() {
    @Override
    public boolean handleMessage(Message message) {
        String error = message.getData().getString("BayunError", "");
        return false;
    }
};

bayunCore.removeMembersExceptList(groupId, groupMembers, removeCallingMember, success, failure);
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
import com.bayun_module.GroupMember

val companyEmployeeId = "<companyEmployeeId>"
val companyName = "<companyName>"
val groupId = "<groupId>"
val removeCallingMember = <removeCallingMember>;


val groupMember: GroupMember =  GroupMember()
groupMember.companyEmployeeId = companyEmployeeId
groupMember.companyName = companyName
        
var groupMembers = ArrayList<GroupMember>()
groupMembers.add(groupMember)

// Callbacks to remove a members from a group
val success = Handler.Callback {
    Log.d(TAG, "Members are removed from the Group successfully.")
    false
}

val failure = Handler.Callback {
    val error = it.data.getString("BayunError", "")
    Log.d(TAG, "Error removing the group member")
    false
}

bayunCore.removeMembersExceptList(groupId, groupMembers, removeCallingMember, success, failure)


```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://bayun.gitbook.io/bayuncoresdk-android/6.-groups/7.10-remove-group-members-except-list.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
