0

In this Program : java.util.Base64 library is used.

byte[] bytes = "Test String".getBytes(); String s = Base64.getEncoder().encodeToString(bytes); byte[] b2 = Base64.getDecoder().decode(s); if(b2.equals(bytes)) System.out.println("True"); else System.out.println("False");

Output is: False

  • Try with `Arrays.equals`. – Gábor Bakos Sep 02 '15 at 05:38
  • yup that works Thanks. But why Printing both bytes and b2 gives different output. `bytes : [B@4cdf35a9 b2 : [B@4c98385c` – Pralove Dixit Sep 02 '15 at 05:46
  • For arrays, Java (JVM) do not override the `hashCode`, `equals`, `toString` methods. That is the reason that `equals` practically is just `==` and the `toString` of the two arrays are different. You should use the methods of `java.util.Arrays` for these kinds of tasks when you are working with arrays. – Gábor Bakos Sep 02 '15 at 05:54

0 Answers0