Sunday, 15 February 2015

java - Use method to compare lists -


I am trying to use a method to compare different lists of T2O. In fact, I want to pass two separate lists in a method which would be right or wrong if the elements of an array list use the other. It just gives the truth - and I'm not sure why I should make this false mistake if someone can help me understand this, then it would be great.

  Public category array list test {public static zero main (string [] args {list & lt; String & gt; List1 = New Arrestist & lt; String & gt; (); & Lt; String & gt; List2 = New Arrestist & lt; String & gt; (); List1.add ("cat"); List1.add ("dog"); List1.add ("zebra"); List1.add ("lion"); List1.add ("mouse"); // test value //list2.add("cat "); List2.add ("Lizard"); Boolean doesitcontain = contains (list 1, list2); Println (doesitcontain); } In public stable boolean (list & lt; string & gt; list1, list & lt; string & gt; list2) {Boolean warm content; For (int i = 0; i   

I think your method should be rewritten: In Public Stable Boolean (list & lt; string & gt; list1, list & lt; string & gt; list2) {return list2.containsAll (list1);}

You currently only code The last element of list1 is also in list2 . If you are actually any , Then this would be a simple solution:

  in public stable boolean (list & lt; string & gt; list1, list & lt; string & gt;; list2) {For (string str: list1) {if (list2.contains (str)) {back true;}} description is false; }    

No comments:

Post a Comment