You may have confused it with a List, but that's an array
the general definition is:
ClassOrPrimitive[] varName = new ClassOrPrimitive[arraySize]
ClassOrPrimitive varName[] = ========----==========
Lists are wrappers for Arrays, as Arrays have a static size
if you have an int[] x = new int[10], using int[10] or higher throws an exception (remember, indexes start at 0, meaning size of 10 is 0-9. General size definition: 0 to size - 1)
anyways, this means when you call checked[someINdex] and change the value, you change a specific part of that array
well, it means you can't increase the amount of elements in the array without going through some complicated re-calculations (you can't just say array.add(item) and the size increases)
Lists are wrappers, as they hold an array. The size of the array is changed by the list as needed. Arrays are a primitive datatype, while lists are objects
class List<T>{//<T> is a generic type, meaning anything basically
T[] data = new T[initialSize];
void add(T item){
//size check
//increase if necessary and add
}
That's an extremely simplified version of a List class, but you get the idea
@Ramona no, you can add to a list by calling a method, but to add more items to an array you have to expand the size of it. Which is what the list class does in add
@Ramona Yes
Which is defined with the diamond operator (<>, example: List<Object> ...)
@Ramona No, I just generally suck at explaining because I find it hard to figure out what other people know. I.e. terminology is a massive pitfall when I explain stuff
But I've been working on some neural network (AI) stuff recently, which easily grabs a lot of RAM. So does Gradle, so I have to turn off the neural net to run Android Studio
private void grow(int minCapacity) {
// overflow-conscious code
int oldCapacity = elementData.length;
int newCapacity = oldCapacity + (oldCapacity >> 1);
if (newCapacity - minCapacity < 0)
newCapacity = minCapacity;
if (newCapacity - MAX_ARRAY_SIZE > 0)
newCapacity = hugeCapacity(minCapacity);
// minCapacity is usually close to size, so this is a win:
elementData = Arrays.copyOf(elementData, newCapacity);
}
TL;DR: It calculates the new capacity necessary, copies the elements over to a new list (because you can't increase it, but you can move the elements over to a new list with a different size), and sets the array in the List class (elementData is an array of the data)
the thing is that the more you write down the more you cant find cos its gets complicated :)
so going back to this checed.. you wrote "when you call checked[someIndex] and change the value, you change a specific part of that array" what it means? and again.. how we store these values in this checked variable?