Java Integer Create toInt(Integer n)

Here you can find the source of toInt(Integer n)

Description

Returns either an n converted to int, or 0 if n equals null

License

Open Source License

Parameter

Parameter Description
n a parameter
defaultValue a parameter

Declaration

public static int toInt(Integer n) 

Method Source Code

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

public class Main {
    /**/*from   w  w  w  .  j a  v a  2s.  c  om*/
     * Returns either an n converted to int, or 0 if n equals {@code null} 
     * @param n
     * @param defaultValue
     * @return
     */
    public static int toInt(Integer n) {
        return n != null ? n : 0;
    }

    /**
     * Returns either an n converted to int, or default value if n equals {@code null} 
     * @param n
     * @param defaultValue
     * @return
     */
    public static int toInt(Integer n, int defaultValue) {
        return n != null ? n : defaultValue;
    }
}

Related

  1. toInt(final String value)
  2. toInt(float value)
  3. toInt(int byteSignificance, byte b)
  4. toInt(int[] rgb)
  5. toInt(Integer i)
  6. toInt(long l)
  7. toInt(long l)
  8. toInt(long unsignedInt)
  9. toInt(long[] a)