使用parseint将String转换为int(convert String to int with with parseint)
java
我尝试将int String转换为int
int port = Integer.parseInt(tokens[2]);tokens[2]包含一个String "12777"但是我收到了这个错误
Exception in thread "Thread-2019" java.lang.NumberFormatException: For input string: "12777" at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48) at java.lang.Integer.parseInt(Integer.java:458) at java.lang.Integer.parseInt(Integer.java:499) at inet.ChildServer.hopen(ChildServer.java:88) at inet.ChildServer.run(ChildServer.java:51)编辑:对不起,eclipse中的字符是不可见的,我不明白这是什么。 我有一个这种形式的字符串
command1|Destination-IP|DestinationPort而我只是把它弄乱了
String[] tokens = sentence.split( "[|]" );I try to convert int String to int
int port = Integer.parseInt(tokens[2]);tokens[2] contain a String "12777" But I got this error
Exception in thread "Thread-2019" java.lang.NumberFormatException: For input string: "12777" at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48) at java.lang.Integer.parseInt(Integer.java:458) at java.lang.Integer.parseInt(Integer.java:499) at inet.ChildServer.hopen(ChildServer.java:88) at inet.ChildServer.run(ChildServer.java:51)Edit: Sorry the characters are invisible in eclipse, I don't Understand what is this. I have a String in this form
command1|Destination-IP|DestinationPortand I just splot it
String[] tokens = sentence.split( "[|]" );最满意答案
你可以在传递给Integer.parseInt(tokens [2])之前修剪字符串; 它可能包含空格。
can you trim the string before pass to Integer.parseInt(tokens[2]); it may contain blank spaces.
更多推荐
发布评论