String to binary output in Java

前端 未结 3 1299
[愿得一人]
[愿得一人] 2020-12-31 14:05

I want to get binary (011001..) from a String but instead i get [B@addbf1 , there must be an easy transformation to do this but I don\'t see it.

public stati         


        
3条回答
  •  执笔经年
    2020-12-31 14:29

    When you try to use + with an object in a string context the java compiler silently inserts a call to the toString() method.

    In other words your statements look like

    System.out.println("infobin: " + infoBin.toString())

    which in this case is the one inherited from Object.

    You will need to use a for-loop to pick out each byte from the byte array.

提交回复
热议问题