我是新的,基本的转换问题 [英] I'm new, basic conversion question

查看:46
本文介绍了我是新的,基本的转换问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好。


我想问一下如何确定一个字符串是否也可以是一个整数:

我必须确定,说嘘 " B123" " 20" " 132"这是数字。


谢谢..

hello.

I''d like to ask how to determine if a String could also be an Integer:
I have to determine from, say "boo" "b123" "20" "132" which are numbers.

thanks..

推荐答案

看看 Java 2 Platform SE v1.3.1:Class Integer


并抓住 NumberFormatException 如果字符串不包含可解析的整数将被抛出。
Have a look at Java 2 Platform SE v1.3.1: Class Integer)

and catch the NumberFormatException which will by thrown if the string does not contain a parsable integer.


非常感谢..我做了它所以,在try {}中,工作正常:

thanks a lot.. I made it so, in a try{}, and works fine:

展开 | 选择 | 换行 | 行号


无需转换回String并与compareTo进行比较。优雅的解决方案是这样的:
There is no need for conversion back to String and doing a comparison with compareTo. An elegant solution is like this:
展开 | 选择 | Wrap | 行号


这篇关于我是新的,基本的转换问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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