How to convert String to byte array with default charset in Java

1 Answer

0 votes
package javaapplication1;
 
import java.util.Arrays;
 
public class JavaApplication1 {
 
    public static void main(String[] args) {
 
        try {
 
            String s = "xyz";
 
            byte[] arr = s.getBytes(); // default charset
            System.out.println(Arrays.toString(arr));
 
        } catch (Exception e) {
            System.out.print(e.toString());
        }
    }
}
 
/*
            
run:
      
[120, 121, 122]
   
 */

 



answered Nov 22, 2016 by avibootz
edited Nov 22, 2016 by avibootz

Related questions

1 answer 213 views
1 answer 139 views
139 views asked Oct 26, 2023 by avibootz
2 answers 190 views
4 answers 211 views
2 answers 391 views
3 answers 189 views
...