push element to array of string code example

Example 1: how to add elements in string array in java

Arrays in Java have a defined size, you cannot change it later by adding or removing elements (you can read some basics here). Instead, use a List : ArrayList<String> mylist = new ArrayList<String>(); mylist. add(mystring); //this adds an element to the list.

Example 2: how to add the last area of an array in java

-- how to add objects using an array
car redCar = new Car("Red");
car Garage [] = new Car [100];
Garage[0] = redCar;

Tags:

Java Example