String to char array Java

前端 未结 1 1296
傲寒
傲寒 2020-12-02 12:48

I am stumped on this and I need some fresh eyes, I\'m not sure why this code is doing this.

String string = new String(new char[] {(char) 0x01, (char) 0x02,          


        
相关标签:
1条回答
  • 2020-12-02 13:28

    A string to char array is as simple as

    String str = "someString"; 
    char[] charArray = str.toCharArray();
    

    Can you explain a little more on what you are trying to do?

    * Update *

    if I am understanding your new comment, you can use a byte array and example is provided.

    byte[] bytes = ByteBuffer.allocate(4).putInt(1695609641).array();
    
    for (byte b : bytes) {
       System.out.format("0x%x ", b);
    }
    

    With the following output

    0x65 0x10 0xf3 0x29

    0 讨论(0)
提交回复
热议问题