I’m having trouble returning arrays from a custom method. It compiles fine but I get back:
[Ljava.lang.String;@20cf2c80
Press any key to continue . . .
I use:
System.out.println(getItem(1));
code:
public static String[] getItem(int e) {
String[] stats = new String[7];
String name = "Null";
String desc = "None";
String typeOf = "0";
String attackAdd = "0";
String defenseAdd = "0";
String canSell = "true";
String canEat = "false";
String earnedCoins = "0";
if (e == 1) {
name = "Pickaxe";
desc = "Can be used to mine with.";
typeOf = "2";
}
return new String[] { name, desc, typeOf};
}
Help? :\
The
toString()method of an array object actually doesn’t go through and produce a string representation of the contents of the array, which is what I think you wanted to do. For that you’ll needArrays.toString().The notation
[Ljava.lang.Stringis Java code for aStringarray – in general, the default string representation of an array is[Lfollowed by the type of the array’s elements. Then you get a semicolon and the memory address (or some sort of locally unique ID) of the array.