Best way to combine two class arrays based on class variable value

Using Java, which is the best way to combine two class arrays based on some class value?

Example. We have these two classes:

public class C1{
  public String id="";
  public String value="";
  public String tot="";
}

public Class C2{
 public String id="";
 public String tot="";
}

And at some point in our code, we have two arrays like:

            //id -value - tot
C1 a [] = { {"1","value#1",""}, 
            {"2","value#2",""}, 
            {"3","value#3",""}, 
            {"4","value#4",""}
    };
                //id - tot
    C2 b [] = { {"1","2"}, 
                {"2","11"}, 
                {"4","15"}
};

The final array should look like this:

C1 f [] = { {"1","value#1","2"}, 
            {"2","value#2","11"}, 
            {"3","value#3",""}, 
            {"4","value#4","15"}
};

I am trying to find the best way to achieve this result without reading an array from beginning to end, because here two arrays have only a few lines, but in fact they both can have a length of 100 to + ...

+5
source share
3 answers

Map<String, C1>, - id. , id . TreeHashMap, .

+2

, . , ( ), , .

0

, . , : ) . .
) , - - hashmap, , .
c) - . . - , .
d) , - -. X-, . , , . .
e) Hadoop Map/Reduce - , . , .
f) Hadoop Hive, . .

0
source

All Articles