Let's say there are
List<string> a1 = new List<string>(); List<string> a2 = new List<string>();
Is there way to do like this?
if (a1 == a2) { }
Given two strings, represented as linked lists (every character is a node in a linked list). Write a function compare() that works similar to strcmp(), i.e., it returns 0 if both strings are the same, 1 if the first linked list is lexicographically greater, and -1 if the second string is lexicographically greater.
We can club the Python sort() method with the == operator to compare two lists. Python sort() method is used to sort the input lists with a purpose that if the two input lists are equal, then the elements would reside at the same index positions.
The == operator, known as the equality operator, is used to compare two strings in Java.
Use sort() method and == operator to compare lists The sorted list and the == operator are used to compare the list, element by element.
If you want to check that the elements inside the list are equal and in the same order, you can use SequenceEqual
:
if (a1.SequenceEqual(a2))
See it working online: ideone
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With