0

please tell me how to print out result from Array static method

public static void main(String[] args) {
        System.out.println(add(1, 2));
        String a = "Learn Java";
        System.out.println(test(a));
    }
    public static int add(int a, int b){
       return a + b;
    }
    public static String[] test(String a){
        return a.split("[ ]");
    }

if I print out "add", the result : 3 but when I print out "test", the result show hex number.

Okem
  • 395
  • 1
  • 4
  • 12
  • Is the question: how do I print out the values in an array of Strings? – rob Jul 10 '14 at 10:00
  • First of all why is your split with `[]`, shouldn't it be `a.split(" ")`? The other thing is you are getting a string array return from method `test` and you should use `System.out.println(Arrays.toString(test(a)))` to print that array. – Omoro Jul 10 '14 at 10:02
  • The hex number you get is the hash code of the array. Keep reading about Java ! – PeterMmm Jul 10 '14 at 10:03
  • use `System.out.println(test(a)[0]+" and "+test(a)[1]);` in the 4th line. – Shashish Chandra Jul 10 '14 at 10:09

0 Answers0