K
K
Konstantin Malyarov2015-12-24 12:20:04
Java
Konstantin Malyarov, 2015-12-24 12:20:04

How to return the contents of an array?

There is a method to which the argument is passed as an array of 10 characters.
Then he must present the array as a whole word and return it for further manipulations.

private static String totalunique(String[] unique) {
        for (String stringunique : unique) {
            System.out.print(stringunique);
        }
        return null;
    }

There were problems:
A variable of type String is declared only in the for loop, otherwise it gives an error that a semicolon is missing.
private static String totalunique(String[] unique) {
        String stringunique = null;
        for (stringunique : unique)(здесь будет подчеркнуто красным и говорить expected ;) {
            System.out.print(stringunique);
        }
        return stringunique;
    }

And in the log there will be Error:(29, 14) java: bad initializer for for-loop
How to return stringunique value?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
Gleb Zykov, 2015-12-25
@kataloo

Your best bet is to use the TextUtils.join function in the Android SDK:
TextUtils.join("", unique);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question