我是一名新手程序员,并且被困了很长时间。我有一个字符串数组,希望在将其分成 5 个单词并将其转换为整数作为字符串数组后获取最后一个单词。这是我尝试过的,但还没有接近工作。请问我该怎么做? :(。谢谢
String FailSome = "Tests run: 12, Failures: 4";
String[] words = FailSome.split("\\s+");
for (int i = 0; i < words.length; i++) {
Integer.parseInt(words[4]);
System.out.println(words[i]);
}
最佳答案
我希望, 据我了解,您想拆分 FailSome,
存储在String数组中,并希望将to数组的最后一个值转换为int,
然后显示
我希望这对你有用,
String FailSome = "Tests run: 12, Failures: 4";
String[] words = FailSome.split("\\s");//splitting goes here
int lastindexofarray=(words.length)-1;
int value=Integer.parseInt(words[lastindexofarray]);
System.out.println(value);//if you want to print the converted value
输出:4
谢谢
关于java - 从数组中获取索引并转换它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27168555/