The example in this article describes how Java compares the values of two list to be equal. Share to everyone for your reference. Specifically as follows:
Suppose two queues {1,2,3,4} and {4,3,2,1}, this method is used to compare whether the values contained in these two queues are equal
/**
* Queue comparison
* @param <T>
* @param a
* @param b
* @return/public
static <t extends C omparable<t>> Boolean compare (List<t> A, list<t> b) {
if (a.size ()!= b.size ())
return false;
Collections.sort (a);
Collections.sort (b);
for (int i=0;i<a.size (); i++) {
if (!a.get (i). Equals (B.get (i)), return
false;
return true;
}
The test method is as follows: public
static void Main (string[] args) {
list<integer> a = arrays.aslist (1,2,3,4);
List<integer> B = arrays.aslist (4,3,2,1);
System.out.println (Compare (A, b));
Execution result True
I hope this article will help you with your Java programming.