I tried to solve the problem using java 8, which I already solved using a simple loop. However, I have no idea how to do this. The problem is this:
File1 :
1,sdfasfsf
2,sdfhfghrt
3,hdfxcgyjs
File2 :
10,xhgdfgxgf
11,hcvcnhfjh
12,sdfgasasdfa
13,ghdhtfhdsdf
The output should look like
1,sdfasfsf
10,xhgdfgxgf
2,sdfhfghrt
11,hcvcnhfjh
3,hdfxcgyjs
12,sdfgasasdfa
13,ghdhtfhdsdf
I already have this job basically,
The main logic:
List<String> left = readFile(lhs);
List<String> right = readFile(rhs);
int leftSize = left.size();
int rightSize = right.size();
int size = leftSize > rightSize? leftSize : right.size();
for (int i = 0; i < size; i++) {
if(i < leftSize) {
merged.add(left.get(i));
}
if(i < rightSize) {
merged.add(right.get(i));
}
}
- MergeInputs.java
- Unittest
- The input files are in the src / test / resources / com / linux / test / merge / file of the list of the same repo (only two links are allowed)
However, I boasted that I could easily do this using threads, and now I'm not sure that this can even be done.
Help is really appreciated.
source
share