-1

I have a big problem. I have just try to search a solution, but i don't have find any solution. i have this code

public static String getString() throws IOException {

    String content = null;
    File folder = new File("C:\\Soluzioni.txt");

    content = FileUtils.readFileToString(folder) + "\n";
    String remainingString = content.substring(content.indexOf("["),
            content.lastIndexOf("]") + 1);
    System.out.println(remainingString);
    return remainingString;

}

And this is ok. (For clarity)

OUTPUT :[40,-13,-6,-7,-4] [28,-40,45,-29,37] [-43,19,-24,-9,-45] [26,-41,-28,-16,44]

My problem is now:

public static String[] arg() throws IOException {
    String[] strArray = { getString() };
    System.out.println(strArray);
    return strArray;
}

when i print strArray, i have an error (ECLIPSE show me this: [Ljava.lang.String;@796686c8). I would need my string (remainingString) to become an array of strings(strArray), but that maintained the same format, that is, it was always OUTPUT :[40,-13,-6,-7,-4] [28,-40,45,-29,37] [-43,19,-24,-9,-45] [26,-41,-28,-16,44] but with array format. Thank you very much!

Shreyos Adikari
  • 12,348
  • 19
  • 73
  • 82
nonac
  • 35
  • 7

2 Answers2

6

Arrays are objects too in Java, but they don't override Object's toString() method, which is responsible for the output: [Ljava.lang.String;@796686c8

In other words, this method returns a string equal to the value of:

getClass().getName() + '@' + Integer.toHexString(hashCode())

Use Arrays.toString to generate the expected array output:

System.out.println(Arrays.toString(strArray));
Community
  • 1
  • 1
rgettman
  • 176,041
  • 30
  • 275
  • 357
  • yes,thank you. But later I wanted to pass my array to a different method, in particular, should do so as?. about the code in up, i should use string[] arg() in this method (any solution)? public static void parseClauses(List F, String[] arg, int N) { – nonac Apr 21 '14 at 19:29
2

You have to use Arrays.toString() method which returns a string representation of the contents of the specified array.
Change your system out to System.out.println(Arrays.toString(strArray));

System.out.println(strArray); will print the Object toString value getClass().getName() + '@' + Integer.toHexString(hashCode())

That's why you are getting [Ljava.lang.String;@796686c8).

Please refer http://docs.oracle.com/javase/6/docs/api/java/util/Arrays.html for more information.

Shreyos Adikari
  • 12,348
  • 19
  • 73
  • 82