How compare only items in 2 lists? [closed]












-5















Android 5.0, Java 1.7



I has 2 lists. I need to compare only content of this lists. The order of the elements does not matter.
Example:



[1,2,3,4,5] , [1,2,3,4,5] -> return true

[1,2,3,4] , [1,2,3,4,5] -> return false

[1,3,5,4,2] , [1,2,3,4,5] -> return true









share|improve this question













closed as off-topic by Stultuske, Andrii Omelchenko, Thomas, user6910411, Raedwald Nov 22 '18 at 12:50


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it." – Stultuske, user6910411

If this question can be reworded to fit the rules in the help center, please edit the question.









  • 10





    by writing the code that does that, but we're not a handing out code service.

    – Stultuske
    Nov 22 '18 at 11:03






  • 1





    You an try converting list to SET and then compare them by Collection comparator

    – ahuja007
    Nov 22 '18 at 11:05






  • 3





    duplicate stackoverflow.com/questions/13501142/…

    – K. Dexter
    Nov 22 '18 at 11:06






  • 2





    Possible duplicate of Java ArrayList - how can I tell if two lists are equal, order not mattering?

    – Andrii Omelchenko
    Nov 22 '18 at 11:07
















-5















Android 5.0, Java 1.7



I has 2 lists. I need to compare only content of this lists. The order of the elements does not matter.
Example:



[1,2,3,4,5] , [1,2,3,4,5] -> return true

[1,2,3,4] , [1,2,3,4,5] -> return false

[1,3,5,4,2] , [1,2,3,4,5] -> return true









share|improve this question













closed as off-topic by Stultuske, Andrii Omelchenko, Thomas, user6910411, Raedwald Nov 22 '18 at 12:50


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it." – Stultuske, user6910411

If this question can be reworded to fit the rules in the help center, please edit the question.









  • 10





    by writing the code that does that, but we're not a handing out code service.

    – Stultuske
    Nov 22 '18 at 11:03






  • 1





    You an try converting list to SET and then compare them by Collection comparator

    – ahuja007
    Nov 22 '18 at 11:05






  • 3





    duplicate stackoverflow.com/questions/13501142/…

    – K. Dexter
    Nov 22 '18 at 11:06






  • 2





    Possible duplicate of Java ArrayList - how can I tell if two lists are equal, order not mattering?

    – Andrii Omelchenko
    Nov 22 '18 at 11:07














-5












-5








-5








Android 5.0, Java 1.7



I has 2 lists. I need to compare only content of this lists. The order of the elements does not matter.
Example:



[1,2,3,4,5] , [1,2,3,4,5] -> return true

[1,2,3,4] , [1,2,3,4,5] -> return false

[1,3,5,4,2] , [1,2,3,4,5] -> return true









share|improve this question














Android 5.0, Java 1.7



I has 2 lists. I need to compare only content of this lists. The order of the elements does not matter.
Example:



[1,2,3,4,5] , [1,2,3,4,5] -> return true

[1,2,3,4] , [1,2,3,4,5] -> return false

[1,3,5,4,2] , [1,2,3,4,5] -> return true






java android






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 22 '18 at 11:02









AlexeiAlexei

1,12711024




1,12711024




closed as off-topic by Stultuske, Andrii Omelchenko, Thomas, user6910411, Raedwald Nov 22 '18 at 12:50


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it." – Stultuske, user6910411

If this question can be reworded to fit the rules in the help center, please edit the question.




closed as off-topic by Stultuske, Andrii Omelchenko, Thomas, user6910411, Raedwald Nov 22 '18 at 12:50


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it." – Stultuske, user6910411

If this question can be reworded to fit the rules in the help center, please edit the question.








  • 10





    by writing the code that does that, but we're not a handing out code service.

    – Stultuske
    Nov 22 '18 at 11:03






  • 1





    You an try converting list to SET and then compare them by Collection comparator

    – ahuja007
    Nov 22 '18 at 11:05






  • 3





    duplicate stackoverflow.com/questions/13501142/…

    – K. Dexter
    Nov 22 '18 at 11:06






  • 2





    Possible duplicate of Java ArrayList - how can I tell if two lists are equal, order not mattering?

    – Andrii Omelchenko
    Nov 22 '18 at 11:07














  • 10





    by writing the code that does that, but we're not a handing out code service.

    – Stultuske
    Nov 22 '18 at 11:03






  • 1





    You an try converting list to SET and then compare them by Collection comparator

    – ahuja007
    Nov 22 '18 at 11:05






  • 3





    duplicate stackoverflow.com/questions/13501142/…

    – K. Dexter
    Nov 22 '18 at 11:06






  • 2





    Possible duplicate of Java ArrayList - how can I tell if two lists are equal, order not mattering?

    – Andrii Omelchenko
    Nov 22 '18 at 11:07








10




10





by writing the code that does that, but we're not a handing out code service.

– Stultuske
Nov 22 '18 at 11:03





by writing the code that does that, but we're not a handing out code service.

– Stultuske
Nov 22 '18 at 11:03




1




1





You an try converting list to SET and then compare them by Collection comparator

– ahuja007
Nov 22 '18 at 11:05





You an try converting list to SET and then compare them by Collection comparator

– ahuja007
Nov 22 '18 at 11:05




3




3





duplicate stackoverflow.com/questions/13501142/…

– K. Dexter
Nov 22 '18 at 11:06





duplicate stackoverflow.com/questions/13501142/…

– K. Dexter
Nov 22 '18 at 11:06




2




2





Possible duplicate of Java ArrayList - how can I tell if two lists are equal, order not mattering?

– Andrii Omelchenko
Nov 22 '18 at 11:07





Possible duplicate of Java ArrayList - how can I tell if two lists are equal, order not mattering?

– Andrii Omelchenko
Nov 22 '18 at 11:07












1 Answer
1






active

oldest

votes


















2














A simple method would be to use containsAll method:



if(listOne.containsAll(listTwo) && listTwo.containsAll(listOne)) {
System.out.println("They are equal");
}





share|improve this answer





















  • 1





    If size of lists are same then one comparison is in-off to full-fill check.

    – Chetan Joshi
    Nov 22 '18 at 11:14











  • That's not necessarily true

    – Schidu Luca
    Nov 22 '18 at 11:21


















1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














A simple method would be to use containsAll method:



if(listOne.containsAll(listTwo) && listTwo.containsAll(listOne)) {
System.out.println("They are equal");
}





share|improve this answer





















  • 1





    If size of lists are same then one comparison is in-off to full-fill check.

    – Chetan Joshi
    Nov 22 '18 at 11:14











  • That's not necessarily true

    – Schidu Luca
    Nov 22 '18 at 11:21
















2














A simple method would be to use containsAll method:



if(listOne.containsAll(listTwo) && listTwo.containsAll(listOne)) {
System.out.println("They are equal");
}





share|improve this answer





















  • 1





    If size of lists are same then one comparison is in-off to full-fill check.

    – Chetan Joshi
    Nov 22 '18 at 11:14











  • That's not necessarily true

    – Schidu Luca
    Nov 22 '18 at 11:21














2












2








2







A simple method would be to use containsAll method:



if(listOne.containsAll(listTwo) && listTwo.containsAll(listOne)) {
System.out.println("They are equal");
}





share|improve this answer















A simple method would be to use containsAll method:



if(listOne.containsAll(listTwo) && listTwo.containsAll(listOne)) {
System.out.println("They are equal");
}






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 22 '18 at 11:18

























answered Nov 22 '18 at 11:12









Schidu LucaSchidu Luca

2,834520




2,834520








  • 1





    If size of lists are same then one comparison is in-off to full-fill check.

    – Chetan Joshi
    Nov 22 '18 at 11:14











  • That's not necessarily true

    – Schidu Luca
    Nov 22 '18 at 11:21














  • 1





    If size of lists are same then one comparison is in-off to full-fill check.

    – Chetan Joshi
    Nov 22 '18 at 11:14











  • That's not necessarily true

    – Schidu Luca
    Nov 22 '18 at 11:21








1




1





If size of lists are same then one comparison is in-off to full-fill check.

– Chetan Joshi
Nov 22 '18 at 11:14





If size of lists are same then one comparison is in-off to full-fill check.

– Chetan Joshi
Nov 22 '18 at 11:14













That's not necessarily true

– Schidu Luca
Nov 22 '18 at 11:21





That's not necessarily true

– Schidu Luca
Nov 22 '18 at 11:21



Popular posts from this blog

404 Error Contact Form 7 ajax form submitting

How to know if a Active Directory user can login interactively

TypeError: fit_transform() missing 1 required positional argument: 'X'