The reason you get the "weird" output from System.out.println(f.toString()) is because you are printing an array, not a string. Java array classes do not override the toString() method. Therefore, the toString() method that is called is the one from java.lang.Object that is defined to display the class name of the object and its hashcode identifier. (In this case, the class name of the byte[] class will be "[b".)
I think your confusion arises because you are mentally equating an array of String and byte. There are two reasons why this is conceptually wrong:
In Java, strings are not arrays. The String class is a fully encapsulated class that cannot be attributed to anything else ... except an object.
In Java, String models a sequence of characters, not a sequence of bytes.
The latter is a key difference because there are many possible conversions between sequences of characters and bytes, many of which are losses in one or both directions. When you call "hello".getBytes() , you get the conversion implied by the default character encoding for your platform, but you could specify the getBytes parameter to use a different encoding in the transformation.
source share