Java: Arrays.equals not working -


i have array byte[] of file i've read in. need check first 5 bytes of file. begin did this:

if (ips_bytes[0] != ips_ident[0] && ips_bytes[1] != ips_ident[1] && ips_bytes[2] != ips_ident[2]             && ips_bytes[3] != ips_ident[3] && ips_bytes[4] != ips_ident[4]) {         return "nope!";     } 

this works, doesn't nice , guess it's not efficient. looked other methods , found arrays.equals(). changed code reflect that:

if (!arrays.equals(ips_ident, arrays.copyofrange(ips_bytes, 0, 4))) {         return "baka";     } 

this didn't work, , tried 0, 4 , 1, 5 see if ranges different. missing because looks right? array values correct.

your conditions not equivalent.

first 1 true if pairs of corresponding elements not equal

the second true if exists @ least 1 pair of elements aren't equal

i believe need second code, need fix bit. arrays.copyofrange's third parameter-index exculeded. need

arrays.copyofrange(ips_bytes, 0, 5)) 

or better

arrays.copyofrange(ips_bytes, 0, ips_ident.length)) 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -