Similar solution but using ArrayList.

class Solution {
public boolean validSquare(int[] p1, int[] p2, int[] p3, int[] p4) {
ArrayList<Integer> list = new ArrayList();
setLength(p1,p2, list);
setLength(p1,p3, list);
setLength(p1,p4, list);
setLength(p2,p3, list);
setLength(p2,p4, list);
setLength(p3,p4, list);
if(list.size()!=2)
return false;
if(list.get(0) == 0 || list.get(1) == 0)
return false;
if(list.get(0) / list.get(1) == 2 ||
list.get(0) / list.get(1) == 1/2 )
return true;
return false;
}
public void setLength(int[] p1, int[]p2, ArrayList<Integer> list){
int l1 = p1[0] - p2[0];
int l2 = p1[1] - p2[1];
int len = l1*l1 + l2*l2;
if(!list.contains(len))
list.add(len);
}
}