public String[] decode(String message)
{
String ans1 = "hey";
String ans2 = "hi";
return {ans1 , ans2}; // Is it correct?
}
This above example does not work properly. I am getting a error.
How can I achieve the initial question?
The correct syntax would be
Even though you’ve created two
Strings (ans1andans2) you haven’t created theStringarray (orString[]) you’re trying to return. The syntax shown above is shorthand for the slightly more verbose yet equivalent code:where we create a length 2 String array, assign the first value to
ans1and the second toans2and then return that array.