temp =new char[10];
List Temp=new ArrayList();
Temp.add(temp);
//Another object (Listemp)
char[ ] Temp;
Temp =(char[ ]) temp.get(0);
Error Occurred java.lang.IndexOutOfBoundsException
So we're going to take the char[] form of the list I want to move to a char[] array of other objects, what should I do?
java list
If the current example is in the same block, even the IndexOutOfBoundsException error cannot be checked.
It's easy to answer if you give me an example correctly.
I think you're trying to do the following, as I understand. I don't know if that's right
char[] tempArray = new char[10];
System.out.println(tempArray.hashCode());
List tempList = new ArrayList();
tempList.add(tempArray);
char[] targetArray = (char[]) tempList.get(0);
System.out.println(targetArray.hashCode());
To summarize the questions,
It is understood that you want to copy the char[]
array in the list to another array.
char[] temp new char[10];
List<char[]> list = new ArrayList<>();
list.add(temp);
// To copy to a new array after this...
char[] copyTarget;
char[] src= list.get(0);
// Create the same size of the new array as the existing array, as follows:
copyTarget = new char[src.length];
// Copy through System.arraycopy.
System.arraycopy(src, 0, copyTarget, 0, copyTarget.length);
© 2024 OneMinuteCode. All rights reserved.