Using contains on an ArrayList with integer arrays

Arrays can only be compared with Arrays.equals(). You probably want an ArrayList of ArrayLists. ArrayList<ArrayList<Integer>> j = new ArrayList<ArrayList<Integer>>(); ArrayList<Integer> w = new ArrayList<Integer>(); w.add(1); w.add(2); j.add(w); ArrayList<Integer> t = new ArrayList<Integer>(); t.add(1); t.add(2); return j.contains(t); // should return true.

Arrays and -contains – test for substrings in the elements of an array

It looks like your misconception was that you expected PowerShell’s -contains operator to perform substring matching against the elements of the LHS array. Instead, it performs equality tests – as -eq would – against the array’s elements – see this answer for details. In order to perform literal substring matching against the elements of an … Read more

What does Collection.Contains() use to check for existing objects?

List<T>.Contains uses EqualityComparer<T>.Default, which in turn uses IEquatable<T> if the type implements it, or object.Equals otherwise. You could just implement IEquatable<T> but it’s a good idea to override object.Equals if you do so, and a very good idea to override GetHashCode() if you do that: public class SomeIDdClass : IEquatable<SomeIDdClass> { private readonly int _id; … Read more

Using contains() in LINQ to SQL

Looking at the other attempts saddens me 🙁 public IQueryable<Part> SearchForParts(string[] query) { var q = db.Parts.AsQueryable(); foreach (var qs in query) { var likestr = string.Format(“%{0}%”, qs); q = q.Where(x => SqlMethods.Like(x.partName, likestr)); } return q; } Assumptions: partName looks like: “ABC 123 XYZ” query is { “ABC”, “123”, “XY” }

jQuery :contains selector to search for multiple strings

Answer To find li‘s that have text containing BOTH Mary AND John: $(‘li:contains(“Mary”):contains(“John”)’) To find li‘s that have text containing EITHER Mary OR John: $(‘li:contains(“Mary”), li:contains(“John”)’) Explanation Just think of the :contains as if it was a class declaration, like .class: $(‘li.one.two’). // Find <li>’s with classes of BOTH one AND two $(‘li.one, li.two’). // … Read more

tech