char\byte\String

byte:字节/char:字符/String:字符串

View Code
 1 package com.app;
2
3 public class app {
4
5 /**
6 * @param args
7 */
8 public static void main(String[] args) {
9 // TODO Auto-generated method stub
10 String str1 = "hello, world!!";
11 String str2 = "你好!!";
12 String str3 = "hello,world 你好!!";
13
14 char[] carray;
15 carray = str2.toCharArray();
16 for(int i = 0; i < carray.length; i++){
17 System.out.println(carray[i]);
18 }
19
20 byte[] array;
21 array = str1.getBytes();
22 for(int i = 0; i < array.length; i++){
23 System.out.println((char)array[i]);
24 }
25
26 char[] carray1;
27 carray1 = str3.toCharArray();
28 for(int i = 0; i < carray1.length; i++){
29 System.out.println(carray1[i]);
30 }
31 }
32 }



原文地址:https://www.cnblogs.com/fredric/p/2358598.html