In the below example I have created extend array function. Here first I have define array length then extend new array value. You can see below program it will clearly describe to extend array after initialization by creating an new array.
public class Main {
public static void main(String[] args) {
String[] names = new String[] { "A", "B", "C" };
//Define array length
String[] extended = new String[7];
//extend new array
extended[3] = "D";
extended[4] = "E";
extended[5] = "F";
extended[6] = "G";
// check value and length
System.arraycopy(names, 0, extended, 0, names.length);
for (String str : extended){
System.out.println(str);
}
}
}
output : A
B
C
D
E
F
G
0 Comment(s)