一个静态方法parseInt(char []),它将数字字符数组转换为int值

时间:2015-10-02 20:41:02

标签: java arrays casting

这是我的代码

public static int[] parseInt(char[] myChar)
{      
    int[] myInt = new int[myChar.length];
    for(int x = 0; x < myChar.length; x++)
    {
                myInt[x] = (int)myChar[x];
    }
    return myInt;
}

当我System.out.println(object.parseInt(myChar));的值为{'1','2','3'}时,我希望它会使用myInt的相应unicode值打印{'1','2','3'}

相反,我得到[I@15db9742

关于我做错的任何想法?

1 个答案:

答案 0 :(得分:0)

那是因为你正在打印对象,因此java显示:

[I - the name of the type (in this case it is one dimensional [ array of int) 
@ - joins the string together
15db9742the hashcode of the object.
默认情况下

内存地址。您可以使用:

System.out.println(Arrays.asList(parseInt(array)));