M
M
Makaron30002021-07-08 13:40:32
Java
Makaron3000, 2021-07-08 13:40:32

Why doesn't it output an empty array?

The bottom line is that if a null string is passed as an argument, then you need to display an empty array, but it is not displayed, what's the matter?

public static char[] removeLetter(String arg) {
        if(arg == null) {
            return arg.toCharArray();
        }
        String x = arg.toLowerCase().replace('r','!');
        char[] array = x.toCharArray();
        return array;
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Zagaevsky, 2021-07-08
@zagayevskiy

At you in this place 100% NullPointerException. In Java, you can't call methods on null references. You can create an array by hand: new char[0]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question