Java Integer Create toIntegerFromObj(Object obj)

Here you can find the source of toIntegerFromObj(Object obj)

Description

Tenta transformar um obj em inteiro, caso nao consiga retorna null

License

Apache License

Parameter

Parameter Description
obj a parameter

Declaration

public static Integer toIntegerFromObj(Object obj) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**/*www  .  j  av  a 2 s  .  c o  m*/
     * Tenta transformar um obj em inteiro, caso nao consiga retorna null
     * @param obj
     * @return
     */
    public static Integer toIntegerFromObj(Object obj) {
        try {
            return obj != null ? new Integer(obj.toString()) : null;
        } catch (Exception e) {
        }
        return null;
    }

    /**
     * Transforma um objeto em String<br>
     * Caso obj seja nulo retorna nulo.
     * 
     * @param obj
     * @return
     */
    public static String toString(Object obj) {
        return obj != null ? obj.toString() : null;
    }
}

Related

  1. toIntegerArray(final int[] array)
  2. toIntegerArray(final int[] ints)
  3. toIntegerArray(String text, String delimiter)
  4. toIntegerArray(String... values)
  5. toIntegerByObject(Object obj)
  6. toIntegerObject(boolean bool)
  7. toIntegerObject(Boolean bool, Integer trueValue, Integer falseValue, Integer nullValue)
  8. toIntegerOrNull(String s)
  9. toIntegers(String[] values)