当前位置: 代码迷 >> J2SE >> 字符串怎么转换成数组
  详细解决方案

字符串怎么转换成数组

热度:240   发布时间:2016-04-24 02:32:00.0
字符串如何转换成数组
字符串如何转换成数组

------解决方案--------------------
不知道lz具体说的怎么转化成数组,我列出来一下:
String s = “hello“;
1.把一个String整个转化成一个数组:Arrays.asList(s)
2.把String中的每个字母转化成一个数组的成员: s.toCharArray()
3,如果String中包含特殊字符,不需要的话,你可以split转化成数组
------解决方案--------------------
Java code
public class Test {        public Object[] toArray(String str){        int length=str.length();        Object[] o=new Object[length];        for(int i=0;i<length;i++){            o[i]=str.charAt(i);        }        return o;    }        public static void main(String[] args) {        Object[] o=new Test().toArray("fhdifhe你oia");        for (int i = 0; i < o.length; i++) {            System.out.print(o[i]+" ");        }    }}打印输出:f h d i f h e 你 o i a
  相关解决方案