Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

how to add element to end of array java

public static void main(String[] args) {
    int[] array = new int[] {1, 2, 3};
    System.out.println(Arrays.toString(array));
    array = Arrays.copyOf(array, array.length + 1); //create new array from old array and allocate one more element
    array[array.length - 1] = 4;
    System.out.println(Arrays.toString(array));
}
Comment

append element to head of array java

// using deque
Deque<String> deque = new LinkedList<>();
deque.add("two");
deque.add("one");
deque.addFirst("three");
//prints "three", "two", "one"
Comment

PREVIOUS NEXT
Code Example
Java :: Array list deep copy 
Java :: Spring boot enable openapi swagger accessed 
Java :: viewpager2 dependency 
Java :: okhttp post 
Java :: spring boot base url 
Java :: fill two dimensional array java 
Java :: export java_home linux 
Java :: java enums 
Java :: java create unmodifiable list 
Java :: get minimum of array java 
Java :: java mongodb find with multiple conditions 
Java :: java print pdf to printer 
Java :: intellisense for eclipse java 
Java :: java localtime 
Java :: javafx textarea size 
Java :: worldedit api paste schematic 
Java :: Using enum values as string literals 
Java :: java running sum of array 
Java :: gradle could not determine java versionAdd Answer 
Java :: android studio change button color programmatically 
Java :: check folder for files java 
Java :: calling activity method from fragment: 
Java :: how to find palindrome numbers in java 
Java :: java display message 
Java :: how to add a list in a list java 
Java :: java stop script 
Java :: palindrome java 
Java :: java string literals 
Java :: get key from value hashmap 
Java :: java extends 
ADD CONTENT
Topic
Content
Source link
Name
6+7 =