java - Getting an element from a Set -


Why not set provides an operation to get an element that is another element Is equal?

  set & lt; Foo & gt; Set = ...; ... fu fu = new foo (1, 2, 3); Foo bar = set. Gate (af); // Foo   

I can ask that there is an element equal to set in bar So why can not I get that element? To clarify, the par method is overridden, but it only checks one field, not all, so two Foo Objects are considered equal to actually have different values, so I can not just use foo .

"post-text" itemprop = "text"

Element near you There is no other option, but to use the iterator:

  in public static zero Net (string [] Args) {Set  Set = New Hashet  (); Set (New Foo ("Halo"); (Iterator & Lt; Fu & gt; ; This = set; nitator (); it.hasNext ();) {FU F = it.NET (); if (f.equals (new Foo) ("Hello")) System.out.println ("foo Found ");}} Fixed square fu {string string; Foo (string string) {this.string = string;} @ Override Public Ent Hashod () {Return String.hashCode ();} @ Override Public Boolean Par (Object obj) {Return String. Angle (((foo) ozje). String); }}    

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -