java大神进,如何吧字符串转化为int类型数组,例如:将String=0101101111转化为 int a[i]={0101101111}

[复制链接]
查看11 | 回复5 | 2011-11-7 14:07:01 | 显示全部楼层 |阅读模式
转为成int a[] 也应该是 {0,1,0,1,1,0,1,1,1,1}吧。public class Test {public static void main(String[] args) {String str="0101101111";String temp;int a[] = new int[str.length()];for(int i=0;i<str.length();i++){temp =""+str.charAt(i);a=Integer.parseInt(temp);//输出测试一下:System.out.println(a);...
回复

使用道具 举报

千问 | 2011-11-7 14:07:01 | 显示全部楼层
多个值也可以.如果你只有一个值 直接 i[k]=Integer.parseInt("0101101111");public static void main(String[] args) {String aStr="0101101111,010110112,010110111,"; String []a =aStr.split(",");...
回复

使用道具 举报

千问 | 2011-11-7 14:07:01 | 显示全部楼层
public class StringToIntArray {static int [] parseStringToIntArray(String str){int []num = new int[str.length()];for(int i=0;i<str.length();i++){num = str.char...
回复

使用道具 举报

千问 | 2011-11-7 14:07:01 | 显示全部楼层
String intString = "8982";int i = Integer.parseInt(intString);...
回复

使用道具 举报

千问 | 2011-11-7 14:07:01 | 显示全部楼层
两种,一个是用正则。而是直接转...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行