Java – int error cannot dereference?

My constructor is wrong. I don't know how to fix it? I am a beginner of Java This is an example exercise I'm trying to learn:

/** 
 * Create an array of size n and store a copy of the contents of the
 * input argument
 * @param intArray array of elements to copy 
*/
public IntArray11(int[] intArray)
{
    int i = 0;
    String [] Array = new String[intArray.length];
    for(i=0; i<intArray.length; ++i)
    {
    Array[i] = intArray[i].toString();
    }
}

Solution

Int is not an object in Java (it is a primitive), so you can't call methods on it

A simple way to solve it is to use integer toString(intArray[i])

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>