I need to have the following declarations:
private static String[] BASE = new String[] { "a", "b", "c" };
private static String[] EXTENDED = BASE + new String[] { "d", "e", "f" };
The first line declares a string array with three (or more) string values. The second line should declare a string array with all the string values from BASE and then add three (or more) string values.
Is this possible? If yes... how?
Not like that, no. You can use:
private static String[] EXTENDED = new String[BASE.length + 3];
static {
System.arraycopy(BASE, 0, EXTENDED, 0, BASE.length);
EXTENDED[BASE.length] = "d";
EXTENDED[BASE.length + 1] = "e";
EXTENDED[BASE.length + 2] = "f";
}
Or write a method to concatenate two arrays, then call it with:
private static String[] BASE = new String[] { "a", "b", "c" };
private static String[] EXTENDED =
ArrayUtils.concat(BASE, new String[] { "d", "e", "f" });
I don't know of such a method in the JRE, but it wouldn't be hard to write - or use the streams API if you want.
See more on this question at Stackoverflow