Java String to Int convertStringToInteger(String s)

Here you can find the source of convertStringToInteger(String s)

Description

Converts a string to Integer.

License

Open Source License

Parameter

Parameter Description
String s

Return

Integer

Declaration

public static Integer convertStringToInteger(String s) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**//from w  w w . j ava2s  . c o  m
     * Converts a string to Integer. Non-numeric characters are excluded (example: string "   # J1001 " converted to Integer 1001). 
     * @param String s
     * @return Integer
     */
    public static Integer convertStringToInteger(String s) {
        Integer _integer = null;
        if (s != null) {
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < s.length(); i++) {
                if (Character.isDigit(s.charAt(i))) {
                    sb.append(s.charAt(i));
                }
            }
            if (sb.length() > 0) {
                int id = Integer.parseInt(sb.toString());
                _integer = new Integer(id);
            }
        }
        return _integer;
    }
}

Related

  1. convertStringToInt(String number)
  2. convertStringToInt(String str)
  3. convertStringToInt(String value)
  4. convertStringToInteger(String num)
  5. convertStringToInteger(String s)
  6. convertStringToInteger(String string)
  7. convertStringToInteger(String strParaConvert)
  8. convertStringToInteger(String value)
  9. convertStringToInteger(String value)