如下代码: String str = "opqrst"; char[] arr2 = str.toCharArray(); //把字符串str转换成字符数组arr2 byte[] arr3 = str.getBytes(); //把字符串str转换成字节数组arr3 for(char element : arr2) System.out.print(arr+" "); System.out.println(); //只为换行 for(byte element : arr3) System.out.print(arr+" ");
结果是:
字符数组和字节数组遍历的话,不能用增强for循环吗?
|