You can collect a map from this array:
String[] arr = {"A123", "blue", "A456", "red", "green",
"B111", "purple", "C444", "blue", "green", "yellow", "pink"};
Map<String, List<String>> map = new LinkedHashMap<>();
// assume that first is the 'primary' element
List<String> list = null;
for (String str : arr) {
// if this is a 'primary' element
// regex:
// \\D{1} - first character is non-digit
// \\d+ - non-empty sequence of digits
if (str.matches("\\D{1}\\d+")) {
// put new entry into the map and initialise new list
list = map.computeIfAbsent(str, el -> new ArrayList<>());
} else {
// otherwise, add the 'secondary' element to the list
list.add(str);
}
}
// output
map.forEach((k, v) -> System.out.println(k + "=" + v));
//A123=[blue]
//A456=[red, green]
//B111=[purple]
//C444=[blue, green, yellow, pink]
// convert a map to a 2d array, if needed
String[][] arr2d = map.entrySet().stream()
.map(entry -> Stream
.concat(Stream.of(entry.getKey()), entry.getValue().stream())
.toArray(String[]::new))
.toArray(String[][]::new);
// output
Arrays.stream(arr2d).map(Arrays::toString).forEach(System.out::println);
//[A123, blue]
//[A456, red, green]
//[B111, purple]
//[C444, blue, green, yellow, pink]