public class Example {
public static void main(String[] args) {
int[] numbers = {1,2,3};
// copy a new array
int[] newNumbers = new int[numbers.length+1];
for(int i=0; i<numbers.length;i++){
newNumbers[i] = numbers[i];
}
newNumbers[numbers.length]=4;
}
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter