I want to store as many elements as desired by the user in an array.But how do i do it??,If i were to create an array,i must do so with a fixed size. Every time a new element is added to the array and the array becomes full,i want to update its size by '1'.I tired various types of code..but.it did not work out.It would be of great help if yall could give me some solutions regarding it..in code if possible.Thank You
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
Use an ArrayList. The size it automatically increased if you try to add to a full ArrayList.
By using copyOf method in
java.util.Arrays
classString[]
size is increment automatically / dynamically.Output:
You can't. You can either create a new array and move the items to that array - Or you can use an ArrayList.
On a low level you can do it this way:
Arrays.copyOf() is doing same thing.
You can create a temporary array with a size that is one element larger than the original, and then copy the elements of the original into the temp, and assign the temporary array to the new one.
You can change the size in various ways, but the same idea applies.