爪哇 - 在数组转换字符串翻番 [英] Java - converting String in array to double

查看:89
本文介绍了爪哇 - 在数组转换字符串翻番的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我坚持这个pretty愚蠢的事情;

I'm stuck with this pretty silly thing;

我有这样一个文本文件;

I got a textfile like this;

您好:: 140.0 ::再见

Hello::140.0::Bye

我用其切分为一个字符串数组;

I split it into a string array using;

LS = line.split("::");

然后我尝试包含数字数组值转换为双,这样的;

Then I try to convert the array values containing the number to a double, like this;

Double number = Double.parseDouble(LS[1]);

不过,我得到以下错误消息;

But I get the following error message;

异常线程main
  java.lang.ArrayIndexOutOfBoundsException:
  1

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1

有没有人有任何想法,为什么不起作用?

Does anyone have any idea why this doesn't work?

推荐答案

我认为这是与读取文件有问题。你尝试拆分后印刷生产线和LS也的内容?

I think it's a problem with reading the file. Did you try printing line and also the contents of LS after splitting?

这篇关于爪哇 - 在数组转换字符串翻番的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆