I'm trying to adjust the size of an array using imported java.util.Arrays using Arrays.copyOf Although for some reason the console is output, the array length is 4 as it is supposed to be when I try and assign a value to anything in array row number 4, it will give me a line Giving a nullPointerException where it is going to specify the value of something Cross the line number 4. Can anybody explain this to me?
import java.util.Arrays; Static import java.lang.System.out; Public Class Main {Static EntTT [] [] = New Ent [3] [3]; Public static zero main (string [] args) {ttt = erase. Copyoff (ttt, 4); Out.print (TTT.length); TTT [3] [0] = 2; }} This gives me an output:
"4Exception" main in the thread "java.lang.NullPointerException main.main (main.java: 13) Does anyone know why this is happening, on the one hand, there is also a better way for me to note where the size can be changed? If so, then Give me some example code!
to:
specified Copy the array, sorting or padding with tap (if necessary) ) So the length specified in the copy is: For any index that is valid in the copy but not the original, the copy will be empty, such index will be present if and only if the specified length exceeds the original array. The resulting array as the basic array
What happens is that the array size increases, so a new reference for int [3] status TTT [ 3] and this document states As has been started with null . The fact is that an initial type of array does not mean that it should start internal arrays in itself too. Try:
TTT = Arrays.copyOf (TTT, 4); TTT [3] = new int [3];
Comments
Post a Comment