Logic to check if the String is a valid number or not
本问题已经有最佳答案,请猛点这里访问。
利用该逻辑AM to check if the valid number is a字符串recievied or notP></
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | package com; public class Test { public static void main(String args[]) { String str ="122"; boolean b = isNumb(str); System.out.println(b); } public static boolean isNumb(String str) { String s = str; for (int i = 0; i < s.length(); i++) { if (!Character.isDigit(s.charAt(i))) return false; } return true; } } |
我想在深圳多线程环境中使用this where there can be at a 800—900并发用户时,请让我知道,如果有任何队列has this环槽孔or not??P></
请分享你的视图P></
谢谢提前P></
我会使用正则表达式:P></
1 2 3 |
返回true for to add an optional太负面的号码,最好的短跑。P></
1 | return str.matches("-?\\d+"); |
我会给你简单的to check if the following is a number:字符串P></
1 2 3 4 5 | try { final Integer i = Integer.parseInt("Your String"); } catch(final NumberFormatException nfe) { //String is no number } |
如果字符串validating given for valid number is(not just integer):P></
1 | boolean b = str.matches("^[+-]?(?=.)\\d*(\\.\\d+)?$"); |
there are better to check if字符串方式such as is a number,使用正则表达式。P></
1 | s.matches("^-?\\d+(\\.\\d)?$") |
将easily whether the number is皮卡字符串S,where is your字符串。P></