add an element to int [] array in java
arrays, java
Solution
The length of an array is immutable in java. This means you can't change the size of an array once you have created it. If you initialised it with 2 elements, its length is 2. You can however use a different collection.
List<Integer> myList = new ArrayList<Integer>();
myList.add(5);
myList.add(7);
And with a wrapper method
public void addMember(Integer x) {
myList.add(x);
};
Problem
Want to add or append elements to existing array ``` int[] series = {4,2}; ``` now i want to update the series dynamically with new values i send.. like if i send 3 update series as `int[] series = {4,2,3};` again if i send 4 update series as `int[] series = {4,2,3,4};` again if i send 1 update series as `int[] series = {4,2,3,4,1};` so on How to do it???? I generate an integer every 5 minutes in some other function and want to send to update the `int[] series` array..