Filtering conversation by filter type and value I have been assigned to developed a feature that filters a conversation. For example, I want to filter the conversation by user id then export it to something either JSON or text file. In this case, I created a class that handles the filters like this.

import java.util.ArrayList;
import java.util.List;

/**
 * Represents the filter that operates the filter functions for messages
 *
 * @author Muhammad
 */
public class Filter {

    String filterType;
    String argumentValue;

    //Constructor that takes a parameter of filter type and argument value.
    public Filter(String filterType, String argumentValue) {
        this.filterType = filterType;
        this.argumentValue = argumentValue;
    }

    //Method that filters a conversation by a specific user and return filterd conversation.
    public static Conversation filterByUser(Conversation conversation, String specificUser) {
        List&lt;Message&gt; messageList = new ArrayList&lt;&gt;();
        //Filter by used id
        for (Message message : conversation.messages) {
            if (message.senderId.equals(specificUser)) {
                messageList.add(message);
                Conversation filteredConversation = new Conversation(conversation.name, messageList);
                conversation = filteredConversation;
            }
        }
        return conversation;
    }

    //Method that filters a conversation that contains a specific keywod and returns filterd conversation.
    public static Conversation filterByWord(Conversation conversation, String specificWord) {
        List&lt;Message&gt; messageList = new ArrayList&lt;&gt;();
        //Filter by keyword
        for (Message message : conversation.messages) {
            if (message.content.contains(specificWord)) {
                messageList.add(message);
                Conversation filteredConversation = new Conversation(conversation.name, messageList);
                conversation = filteredConversation;
            }
        }
        return conversation;
    }

    //Method that hides a word in a conversation by a specificword
    public static Conversation hideWord(Conversation conversation, String specificWord) {
        List&lt;Message&gt; messageList = new ArrayList&lt;&gt;();
        //Filter by used id
        for (Message message : conversation.messages) {
            if (message.content.contains(specificWord)) {
                message.content = message.content.replaceAll(specificWord, "*redacted*");
                messageList.add(message);
                Conversation filteredConversation = new Conversation(conversation.name, messageList);
                conversation = filteredConversation;
            }
        }
        return conversation;
    }
}


In another class, I used it inside a method called filter like this.

private void filter(Filter filter, Conversation conversation, String outputFilePath) throws Exception {

        String filterType = filter.filterType; //used to get the type of filter
        String argumentValue = filter.argumentValue;

        //Filterers
        switch (filterType) {
            case "filteruser":
                conversation = Filter.filterByUser(conversation, argumentValue);
                this.writeConversation(conversation, outputFilePath);
                break;
            case "filterword":
                conversation = Filter.filterByWord(conversation, argumentValue);
                this.writeConversation(conversation, outputFilePath);
                break;
            case "hideword":
                conversation = Filter.hideWord(conversation, argumentValue);
                this.writeConversation(conversation, outputFilePath);
                break;
            default:
                this.writeConversation(conversation, outputFilePath);
                break;
        }

    }


This code works, however I'd like feedback on anyways that I can improve the code as I am just a graduate.
I want to mention only one thing especially:

You're using "magic string" to choose your filter types. Instead of doing that (because it's brittle) you are probably better off with an enum:

public enum FilterType {
    USER, WORD, HIDE_WORD
}


Your code would have to adjust a little, but to give a short look into the filter method:

private void filter(Filter filter, Conversation conversation, String outputFilePath) {
    switch (filter.filterType) {
        case FilterType.USER:
            conversation = Filter.filterByUser(conversation, filter.argumentValue);
            writeConversation(conversation, outputFilePath);
            break;
        case FilterType.WORD:
            conversation = Filter.filterByWord(conversation filter.argumentValue);
            writeConversation(conversation, outputFilePath);
            break;
        // ...


This exposes another small improvement possibility in your code.

In every case you will call this.writeConversation with exactly the same arguments. You can move that to outside the switch-case block:

switch (filter.filterType) {
    // ...
}
this.writeConversation(conversation, outputFilePath);


Another last thing I want to recommend is using Path intead of String to refer to outputFilePath. This makes it blatantly obvious, that you're  actually referring to a File. Strings are .. not Paths...