toString method does not work correctly here as it just print bytes in String format.
You can use String’s constructor to get String back.
Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
package org.arpit.java2blog; public class StringContentEqualsExample { public static void main(String[] args) { String str1 = "java2blog"; byte[] bytes=str1.getBytes(); System.out.println(bytes.toString()); String origStr1=new String(bytes); System.out.println(origStr1); } } |
When you run above program, you will get below output:
1 2 3 4 |
[B@e1641c0 java2blog |