Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scala Seq comparison

Tags:

scala

seq

is there a way in Scala to compare two sequences in a way that it returns true if it contains the same elements, regardless of order and repetitions?

Seq("1", "2") vs Seq("2", "1")           => true
Seq("3", "1", "2") vs Seq("2", "1", "3") => true
Seq("1", "1", "2") vs Seq("2", "1")      => true

Thanks

ps this is not a duplicated of this because it also asks to exclude duplicated from the check and it is using SEQ instead of LIST.

like image 960
ab_732 Avatar asked Oct 24 '25 09:10

ab_732


1 Answers

Convert to sets and compare those

like image 72
Jens Schauder Avatar answered Oct 26 '25 02:10

Jens Schauder



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!