字符串转化为二维数组 求助:得到这样的字符串{{11,12,13},{21,22,23},{31,32,33}}怎么转化成数据呢 String[][]s={{"11","12","13"},{"21","22","23"},{"31","32","33"}};??谢谢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 通过下标,获取一个值,这个值 是string类型,将它转化为int类型 String 的split方法,或者tokennizer 方法 先截取出{11,12,13} {21,22,23} {31,32,33} 三个部分然后对每个部分再截取 public class StringToArray { public static void main(String[] args) { String str = "{{11,12,13},{21,22,23},{31,32,33}}"; str = str.replaceAll("\\},\\{", ";");//用分号替换掉中间的“},{” str = str.replaceAll("\\{\\{","").replaceAll("\\}\\}", "");//替换掉“}}”和“{{” String[] temp1,temp2; temp1 = str.split(";"); String[][] s = new String[temp1.length][]; for(int i=0; i<temp1.length; i++) { temp2 = temp1[i].split(","); s[i] = new String[temp2.length]; for(int j=0; j<temp2.length; j++) { s[i][j] = "\"" + temp2[j] + "\""; } } for(int i=0; i<s.length; i++) { for(int j=0; j<s[i].length; j++) { System.out.print(s[i][j] + " "); } } } } Swing怎么保证窗体对象的强引用? SWT运行时动态创建控件无法显示 JAVA做界面开发,数据方面一般用什么技术 有没有做EJB的呀 javac编译错误~ 怎么在log.error()里面把e.printStackTrace的堆栈信息打印出来? RecordSet 如何取得当当包含的记录总数?有什么高效方法? 请问谁在参加Robocode 的设计啊?大家进来说说 好奇怪的初始化问题。 请问具体介绍一下visual cafe吗??有下载的地方吗?多大?有卖的吗? 帮别人发个帖子 现在做项目总是找几个具有类似功能的代码,然后改改。
然后对每个部分再截取
public class StringToArray {
public static void main(String[] args) {
String str = "{{11,12,13},{21,22,23},{31,32,33}}";
str = str.replaceAll("\\},\\{", ";");//用分号替换掉中间的“},{”
str = str.replaceAll("\\{\\{","").replaceAll("\\}\\}", "");//替换掉“}}”和“{{”
String[] temp1,temp2;
temp1 = str.split(";");
String[][] s = new String[temp1.length][];
for(int i=0; i<temp1.length; i++) {
temp2 = temp1[i].split(",");
s[i] = new String[temp2.length];
for(int j=0; j<temp2.length; j++) {
s[i][j] = "\"" + temp2[j] + "\"";
}
}
for(int i=0; i<s.length; i++) {
for(int j=0; j<s[i].length; j++) {
System.out.print(s[i][j] + " ");
}
}
}
}