fork download
  1. import java.util.ArrayList;
  2. import java.util.List;
  3.  
  4. public class Main {
  5. public static void main(String[] args) {
  6. List<int[]> data1 = loadData1();
  7. List<int[]> data2 = loadData2();
  8.  
  9. List<int[]> joinedData = joinData(data1, data2);
  10.  
  11. for (int[] row : joinedData) {
  12. System.out.println("(" + row[0] + "," + row[1] + "," + row[2] + "," + row[3] + "," + row[4] + ")");
  13. }
  14. }
  15.  
  16. private static List<int[]> loadData1() {
  17. List<int[]> data1 = new ArrayList<>();
  18. data1.add(new int[]{1, 2, 3});
  19. data1.add(new int[]{4, 2, 1});
  20. data1.add(new int[]{8, 3, 4});
  21. data1.add(new int[]{4, 3, 3});
  22. data1.add(new int[]{7, 2, 5});
  23. data1.add(new int[]{8, 4, 3});
  24. return data1;
  25. }
  26.  
  27. private static List<int[]> loadData2() {
  28. List<int[]> data2 = new ArrayList<>();
  29. data2.add(new int[]{2, 4});
  30. data2.add(new int[]{8, 9});
  31. data2.add(new int[]{1, 3});
  32. data2.add(new int[]{2, 7});
  33. data2.add(new int[]{2, 9});
  34. data2.add(new int[]{4, 6});
  35. data2.add(new int[]{4, 9});
  36. return data2;
  37. }
  38.  
  39. private static List<int[]> joinData(List<int[]> data1, List<int[]> data2) {
  40. List<int[]> result = new ArrayList<>();
  41.  
  42. for (int[] rowA : data1) {
  43. for (int[] rowB : data2) {
  44. if (rowA[0] == rowB[0]) {
  45. result.add(new int[]{rowA[0], rowA[1], rowA[2], rowB[1], rowB[1]});
  46. }
  47. }
  48. }
  49.  
  50. return result;
  51. }
  52. }
  53.  
Success #stdin #stdout 0.19s 57984KB
stdin
Standard input is empty
stdout
(1,2,3,3,3)
(4,2,1,6,6)
(4,2,1,9,9)
(8,3,4,9,9)
(4,3,3,6,6)
(4,3,3,9,9)
(8,4,3,9,9)