D
dimitri.ognibene
I'm tryng to build a set of int array...
but it doesn't works.. I don't know how to use the api.. please help..
this must output ok but it doesnt, only "azz"
public class Main {
/** Creates a new instance of Main */
static class pica{
int[] data;
public boolean equals(Object a){
return (a instanceof
pica)&&java.util.Arrays.equals(data,((pica)a).data);
}
}
public Main() {
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
int a[]=new int[]{1,2};
int b[]=new int[]{1,2};
pica ap=new pica();
pica bp=new pica();
ap.data=a;
bp.data=b;
java.util.Set<pica> set =new java.util.HashSet<pica>();
set.add(ap);
// if
(set.contains((java.util.List)java.util.Arrays.asList(b)))System.out.println("ok");
if(set.contains(bp)) System.out.println("ok");
else System.out.println("azz");
System.out.println(a.hashCode());
System.out.println(b.hashCode());
System.out.println(java.util.Arrays.asList(a).hashCode());
System.out.println(java.util.Arrays.asList(b).hashCode());
but it doesn't works.. I don't know how to use the api.. please help..
this must output ok but it doesnt, only "azz"
public class Main {
/** Creates a new instance of Main */
static class pica{
int[] data;
public boolean equals(Object a){
return (a instanceof
pica)&&java.util.Arrays.equals(data,((pica)a).data);
}
}
public Main() {
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
int a[]=new int[]{1,2};
int b[]=new int[]{1,2};
pica ap=new pica();
pica bp=new pica();
ap.data=a;
bp.data=b;
java.util.Set<pica> set =new java.util.HashSet<pica>();
set.add(ap);
// if
(set.contains((java.util.List)java.util.Arrays.asList(b)))System.out.println("ok");
if(set.contains(bp)) System.out.println("ok");
else System.out.println("azz");
System.out.println(a.hashCode());
System.out.println(b.hashCode());
System.out.println(java.util.Arrays.asList(a).hashCode());
System.out.println(java.util.Arrays.asList(b).hashCode());