public class State{
String code;
int occurValue;
int name;
}
public class Equi{
String code;
int occurValue;
int macAddress;
}
Having 2 classes of different types.
I'm having a List<State>
and List<equi>
. In these lists if code and occurValue is same, I need to move that to different List.
How can I achieve this, googling gave me so many options line Comparable, Comparator. Let me know which is the most efficient way to achieve this.
Thanks in advance.
If there is no additional information on the lists, then the most efficient algorithm is to compare each element of the one list with each element of the other:
This is O(n * m) (where n is the size of stateList and m is the size of equiList).
If the two lists are sorted, then more efficient algorithms can be used. For example, in pseudocode:
This is O(m + n). Of course, for this to work you will have to write comparison functions (one for comparing a
State
with aState
, one for comparing anequi
with anequi
and one for comparing aState
with anequi
).By the way, Java naming conventions dictate that classes start with a capital letter, so it should be
Equi
, notequi
.