Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compare two string ArrayLists

I have two array lists

  dim Colors1 = New ArrayList
  Colors1.Add("Blue")
  Colors1.Add("Red")
  Colors1.Add("Yellow")
  Colors1.Add("Green")
  Colors1.Add("Purple")

  dim Colors2 = New ArrayList
  Colors2.Add("Blue")
  Colors2.Add("Green")
  Colors2.Add("Yellow")

I would like to find out which colors are missing from Colors2 that are found in Colors1

like image 580
zeroef Avatar asked May 18 '26 04:05

zeroef


1 Answers

Look at using Except method. "This method returns those elements in first that do not appear in second. It does not also return those elements in second that do not appear in first."

So you can just put colors 2 as the first argument and colors1 as the second.

EDIT: I meant you can put colors 1 first and colors 2 as the second.

EDIT2: (per Sean)

var missingFrom2 = colors1.Except(colors2);
like image 119
spinon Avatar answered May 19 '26 20:05

spinon



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!