具有阵列,也许闹分裂 [英] having trouble with arrays and maybe split
本文介绍了具有阵列,也许闹分裂的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
String realstring = "&&&.&&&&";
Double value = 555.55555;
String[] arraystring = realstring.split(".");
String stringvalue = String.valueof(value);
String [] valuearrayed = stringvalue.split(".");
System.out.println(arraystring[0]);
很抱歉,如果它看起来不错。改写了我的手机上。我不断收到 ArrayIndexOutOfBoundsException异常:0
在的System.out.println
。我已经看过并不能弄明白。感谢您的帮助。
Sorry if it looks bad. Rewrote on my phone. I keep getting ArrayIndexOutOfBoundsException: 0
at the System.out.println
. I have looked and can't figure it out. Thanks for the help.
推荐答案
拆分()
需要一个正则表达式作为参数,而不是一个文字字符串。你必须逃脱点:
split()
takes a regexp as argument, not a literal string. You have to escape the dot:
string.split("\\.");
或
string.split(Pattern.quote("."));
或者你也可以简单地使用的indexOf('。')
和子()
来获得两部分你的字符串。
Or you could also simply use indexOf('.')
and substring()
to get the two parts of your string.
而如果目标是获得一个双的整数部分,你也可以简单地使用
And if the goal is to get the integer part of a double, you could also simply use
long truncated = (long) doubleValue;
这篇关于具有阵列,也许闹分裂的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文