I am doing gift (String-type) storage, using arrays, with the maximum 500 million. I want to get the number of used elements in an array like how many gifts are currently in stock, (I.E. I stored 253538 gifts, but I don't know that. Is there a command in Java that can know that there is only 253538 Slots in the array that contain an element). But I don't know how to. Here's the snippet of code I want to use:
static String[] Gifts = new String[500000000];
static int i = 0;
String command, Gift;
while (true) {
//Gift Array Console
String command = scan.next();
if (command == "addgift") {
String Gift = scan.next();
Gifts[i] = Gift;
i++;
}
}