I initially have this code:
String[] A;
String[] B;
List<String> myList= new ArrayList<>(A.length + B.length);
for (int i= 0; i< B.length; i++){
myList.add(A[i]);
myList.add("*".equals(B[i]) ? B[i] : doSomethingWith(B[i]));
}
How to refactor, if you use, preferably Java 8?
If, for example, I have these arrays
A = {"one", "two", "three", "four"}
B = {"five", "six", "seven", "eight"}
At the end of the code, myList will be:
myList = {"one", "five", "two", "six", "three", "seven", "four", "eight"}
source
share