-1

I have this string "5,7,6,1" and I want to make an integer array of the size 4 like this: out={5 7 6 1} which out[0]=5 and out[1]=7 and... actually I want to have the number of the string in an integer array but when I print the out the output is the address of the array out like this: [I@152b6651 what's wrong with this code????

public static void main(String[] args) {
        String a = new String();
        a="5,7,6,1";
        int element, temp = 0, ans = 0,j=0;
        element = a.length() / 2 + 1;
        int[] out = new int[element];
        for (int i = 0; i < a.length(); i++) {
            if (j < element) {
                temp = (int) a.charAt(i);
                if (temp != 44) {
                    ans = ans * 10 + temp;
                } else {
                    out[j] = ans-48;
                    ans=0;
                    j++;
                }
                if(i==a.length()-1){
                    out[j] = ans-48;
                }
            }
        }
        int[] array=new int[element];
        System.out.println(out);
    }
rahele
  • 87
  • 1
  • 1
  • 5

1 Answers1

0

I think you can use:

Integer[] out = new Integer[element];

then print like this:

System.out.println(Arrays.asList(out));
algojava
  • 743
  • 4
  • 9
  • tnx, yes it shows all the elements in array out but I want to do some operations on this array and all my other parameters are int, wouldn't this be hard to work with this parameter? :( – rahele Feb 11 '17 at 12:58
  • I think you can use Integer as the same way using int. – algojava Feb 11 '17 at 12:59