Java String to Int convertStringToInteger(String value)

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

Description

convert the value to integer , it may throw a ParseException

License

Apache License

Parameter

Parameter Description
value String

Declaration

public static Integer convertStringToInteger(String value) 

Method Source Code

//package com.java2s;
/*//from   w w  w. j a  va  2  s.c o  m
 * Copyright 2015 Pegasus Solutions
 * @author Rafael Peres dos Santos
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by
 * applicable law or agreed to in writing, software distributed under the
 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
 * OF ANY KIND, either express or implied. See the License for the specific
 * language governing permissions and limitations under the License.
 *
 * ================================================================================
 *
 * Direitos autorais 2015 Pegasus Solutions
 * @author Rafael Peres dos Santos
 * 
 * Licenciado sob a Licen?a Apache, Vers?o 2.0 ("LICEN?A"); voc? n?o pode usar
 * esse arquivo exceto em conformidade com a esta LICEN?A. Voc? pode obter uma
 * c?pia desta LICEN?A em http://www.apache.org/licenses/LICENSE-2.0 A menos que
 * haja exig?ncia legal ou acordo por escrito, a distribui??o de software sob
 * esta LICEN?A se dar? ?COMO EST????, SEM GARANTIAS OU CONDI??ES DE QUALQUER
 * TIPO, sejam expressas ou t?citas. Veja a LICEN?A para a reda??o espec?fica a
 * reger permiss?es e limita??es sob esta LICEN?A.
 *
 */

public class Main {
    /**
     * convert the value to integer , it may throw a ParseException
     * 
     * @param value {@link String}
     * @return {@link Integer}
     */
    public static Integer convertStringToInteger(String value) {
        return isNotEmpty(value) ? Integer.parseInt(value) : null;
    }

    /**
     * return true if is not empty the str
     * 
     * @param str {@link String}
     * @return boolean
     */
    public static boolean isNotEmpty(String str) {
        return str != null && !str.trim().isEmpty();
    }

    /**
     * return true if is empty the str
     * 
     * @param str {@link String}
     * @return boolean
     */
    public static boolean isEmpty(String str) {
        return str == null || str.trim().isEmpty();
    }

    /**
     * return true if is empty the CharSequence
     * 
     * @param cs {@link CharSequence}
     * @return boolean
     */
    public static boolean isEmpty(CharSequence cs) {
        return cs == null || cs.length() == 0;
    }
}

Related

  1. convertStringToInteger(String num)
  2. convertStringToInteger(String s)
  3. convertStringToInteger(String s)
  4. convertStringToInteger(String string)
  5. convertStringToInteger(String strParaConvert)
  6. convertStringToInteger(String value)
  7. convertStringToInteger(String value)