判断字符串是否可以转换为Integer


判断代码如下:

    private static final List<Character> numList = new ArrayList<Character>() {{
        add('0');
        add('1');
        add('2');
        add('3');
        add('4');
        add('5');
        add('6');
        add('7');
        add('8');
        add('9');
    }};

    private boolean checkCanConvert2Int(String str) {
        boolean result = true;
        int n = str.length();
        while (n-- != 0) {
            if (!numList.contains(str.charAt(n))) {
                result = false;
                break;
            }
        }
        return result;
    }


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM