java - Unable to access my boolean list -
So I have this list & lt; & Gt; Includes Boolean Areas: And I add to this list: So now when I take my list with () loop, using it: myList.get (i); There is something like this in my output console: but I want to do a lot in Theoj objects too I am How can I do this? As the organs do not override the methods from the object class, you get the default string representation That is: If you want to print the content of an array, you can use it. {boolean [arr: myList] {System.out.println (Arrays.toString (arr)) for Alternatively, to create a wrapper class that wraps your boolean array and you can use the methods, and correctly and main: Stable list & lt; Boolean [] & gt; myList = new arreelist & lt; & Gt; ();
Boolean [mybooleanArray = new boolean [8];
[z @ 65e7c41f
getClass () GetName () + '@' + integer.tocestring (hash code ())
; }
I do not know what you are doing with your boolean array with your list , but know that your Small surprises can be passed:
public class test (static list & lt; Boolean [] & gt; myList = new arreelist & lt; & Gt; (); Public static zero main (string [] args) {boolean [arr = arr = {true, wrong}; Boolean [] arr2 = {true, wrong}; MyList.add (Arrival); Println (myList.contains (arr2)); // false}}
equal < / Code>,
toString and
hashode methods.
class MyBooleanArray {Private Boolean [arr] arr; Public namesphere (boolean [] arr) {this.arr = arr; } @ Override Public Ent Hashod () {Final At Prime = 31; Full result = 1; Results = Prime * Result + Arrays.hashCode (arr); Return result; } @ Override Public Boolean Equals (Object OBJE) {If (this == obje) returns is true; If (obj == faucet) return false; If (getClass ()! = Obj.getClass ()) false return; Mayurbiarere Other = (Maybolière) Ob; If (Arrays.equals (arr, other.arr)) false return; Back true; } @ Override public string toasting () {"mybollier [arr =" + Arrays.toString (arr) + "]" "return"; }}
public class exam (static list & lt; MyBooleanArray & gt; myList = new arreelist & lt; & Gt; (); Public Stable Zero Main (string [] Args) {Boolean [arr] arr = {true, wrong}; Boolean [] arr2 = {true, wrong}; myList.add (new MyBooleanArray (arr)); System.out.println (myList.contains (new MyBooleanArray (arr2)); // true system.out.println (myList.get (0)); // mybollier [arr = [true, false]]}}
Comments
Post a Comment