contains list code example

Example 1: c# object list contaion parameters

public class A { public int Id { get; set; } public A(int id) { Id = id; } }

List<A> list = new List<A>() { new A() { Id = 1}, new A() { Id = 2} };

var matches = list.Where(item => item.Id == 1 || item.Id == 2);
// matches = [0, 1]
// can be used like
for (int i = 0; i < matches.Count; i++) { Console.WriteLine(list[i]); }

Example 2: python check if list contains

# To check if a certain element is contained in a list use 'in'
bikes = ['trek', 'redline', 'giant']
'trek' in bikes
# Output:
# True

Example 3: list contains

List<Integer> arr = new ArrayList<Integer>(4);
boolean ans = arr.contains(2);