#87 Removing the Last Object by Field Value

Companies:
VTB
Themes:
JavaCollections & GenericsPractice

Write a remove() method that removes the last A object whose str = "abc":

public class Main {
    public static void main(String[] args) {
        List<A> list = new ArrayList<>() {{
            add(new A("abc"));
            add(new A("fff"));
            add(new A("abc"));
            add(null);
            add(new A(null));
        }};
    }

    public static List<A> remove(List<A> list) {
        ...
    }
}

class A {
    public A(String str) {
        this.str = str;
    }
    public String str;
}

Question review

Mentor
Answer as you would in a real interview. I’ll ask follow-up questions, then compare your answer with the reference answer and show your accuracy as a %.
Sign in to start the dialogue The mentor keeps the context of the current question and your previous messages.
Sign in