KickJava   Java API By Example, From Geeks To Geeks.

Java > Java SE, EE, ME > java > lang > Integer

java.lang
Class Integer

java.lang.Object
  extended by java.lang.Number
      extended by java.lang.Integer
All Implemented Interfaces:
Serializable, Comparable<Integer>
See Also:
Top Examples, Source Code, numberOfTrailingZeros, highestOneBit

public static int bitCount(int i)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public byte byteValue()
See Also:
Number
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[987]byteValue of 250 is -6
By parisjackson { at } yahoo { dot } com on 2004/10/02 12:01:12  Rate
Integer i1 = new Integer (  250  ) ; 
         byte b = i1.byteValue (  ) ; 
         System.out.println (  i1.toString (  )   ) ; 
         System.out.println (  b  ) ; 
         i1 = new Integer ( 257 ) ; 
         b = i1.byteValue (  ) ; 
         System.out.println (  i1.toString (  )   ) ; 
         System.out.println (  b  ) ; 
         i1 = new Integer ( 512 ) ; 
         b = i1.byteValue (  ) ; 
         System.out.println (  i1.toString (  )   ) ; 
         System.out.println (  b  ) ; 
         //outputs the line: 
         // 250 
         // -6 
         // 257 
         // 1 
         // 512 
         // 0 
 


public int compareTo(Integer anotherInteger)
See Also:
Comparable, compareTo
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[988]Integer comparison
By Jesse L { dot } Jackson - parisjackson { at } yahoo { dot } com on 2004/10/02 12:09:44  Rate
Integer i1 = new Integer (  1  ) ; 
         Integer i2 = new Integer (  1  ) ; 
         Integer i3 = new Integer (  2  ) ; 
         Integer i4 = new Integer (  -2  ) ; 
  
  
         if (  i1.compareTo (  i2  )  == 0  )  
             System.out.println ( "Equal" ) ; 
         else {  
             System.out.println ( "Not Equal" ) ; 
             if (  i1.compareTo (  i2  )  == 1  )  
                 System.out.println ( "i1 greater than i2" ) ; 
             else System.out.println ( "i1 less than i2" ) ; 
          }  
  
  
         if (  i1.compareTo (  i3  )  == 0 )  
             System.out.println ( "Equal" ) ; 
         else {  
             System.out.println ( "Not Equal" ) ; 
             if (  i1.compareTo (  i3  )  == 1  )  
                 System.out.println ( " i1 greater than i3" ) ; 
             else System.out.println ( " i1 less than i3" ) ; 
          }  
  
  
         if (  i1.compareTo (  i4  )  == 0 )  
             System.out.println ( "Equal" ) ; 
         else {  
             System.out.println ( "Not Equal" ) ; 
             if (  i1.compareTo (  i4  )  == 1  )  
                 System.out.println ( " i1 greater than i4" ) ; 
             else System.out.println ( " i1 less than i4" ) ; 
          }  
  
  
         //outputs the lines: 
         // Equal 
         // Not Equal 
         // i1 less than i3 
         // Not Equal 
         // i1 greater than i4 
 


public int compareTo(Object o)
See Also:
Comparable
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[703]_
By Anonymous on 2005/07/14 14:19:20  Rate
Integer result = 144 
             if  ( result.compareTo ( 144 )  == 0 )  
                 return true; 
             else return false;


public static Integer decode(String nm)
                      throws NumberFormatException
See Also:
parseInt(java.lang.String, int)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public double doubleValue()
See Also:
Number
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[990]Convert integer to double
By Jesse L { dot } Jackson - parisjackson { at } yahoo { dot } com on 2004/10/02 14:25:05  Rate
Integer i1 = new Integer (  1  ) ; 
         double d = i1.doubleValue (  ) ; 
         System.out.println (  d  ) ; 
         //outputs the line: 
         // 1.0 
 


public boolean equals(Object obj)
See Also:
Hashtable, Object.hashCode()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[986]_
By parisjackson { at } yahoo { dot } com on 2004/10/02 11:47:56  Rate
Integer i1 = new Integer (  1  ) ; 
 Integer i2 = new Integer (  1  ) ; 
 Integer i3 = new Integer (  2  ) ; 
  
  
 if (  i1.equals (  i2  )   )  
     System.out.println ( "Equal" ) ; 
 else 
     System.out.println ( "Not Equal" ) ; 
  
  
 if (  i1.equals (  i3  )   )  
     System.out.println ( "Equal" ) ; 
 else 
     System.out.println ( "Not Equal" ) ; 
  
  
 //outputs the lines: 
 // Equal 
 // Not Equal 
 


public float floatValue()
See Also:
Number
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[991]Convert integet to float
By Jesse L { dot } Jackson - parisjackson { at } yahoo { dot } com on 2004/10/02 14:27:03  Rate
Integer i1 = new Integer (  1  ) ; 
 float f = i1.floatValue (  ) ; 
 System.out.println (  f  ) ; 
 //outputs the line: 
 // 1.0


public static Integer getInteger(String nm)
See Also:
System.getProperty(java.lang.String, java.lang.String), System.getProperty(java.lang.String)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static Integer getInteger(String nm,
                                 int val)
See Also:
System.getProperty(java.lang.String, java.lang.String), System.getProperty(java.lang.String)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static Integer getInteger(String nm,
                                 Integer val)
See Also:
decode(java.lang.String), System.getProperty(java.lang.String, java.lang.String), System.getProperty(java.lang.String), valueOf(java.lang.String, int)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public int hashCode()
See Also:
Hashtable, Object.equals(java.lang.Object)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static int highestOneBit(int i)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public Integer(int value)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[975]_
By parisjackson { at } yahoo { dot } com on 2004/10/02 11:33:44  Rate
int i = 23; 
 Integer i1 = new Integer ( i ) ; 
 System.out.println (  i1.intValue (  )   ) ;


public Integer(String s)
        throws NumberFormatException
See Also:
parseInt(java.lang.String, int)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[974]_
By parisjackson { at } yahoo { dot } com on 2004/10/02 11:32:15  Rate
String s = "9"; 
 Integer i1 = new Integer ( s ) ; 
 int i = i1.intValue (  ) ; 
 System.out.println ( i ) ;


public int intValue()
See Also:
Number
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[85]convert the String to ahexadecimal
By Anonymous on 2004/05/20 09:11:09  Rate
//read the background color parameter 
 String bgColorStr=getParameter ( "bg_color" ) ; 
 int intvalue; 
 //convert the String to an integer, base is 16  ( hexadecimal )  
 intvalue=Integer.parseInt ( bgColorStr, 16 ) ; 
 


public long longValue()
See Also:
Number
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static int lowestOneBit(int i)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static final int MAX_VALUE
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[984]Integer max value
By parisjackson { at } yahoo { dot } com on 2004/10/02 11:43:28  Rate
int i = Integer.MAX_VALUE; 
 System.out.println (  i  ) ; 
  
  
 //outputs the line 
 // 2147483647 
 // 
 //MAX_VALUE is a constant - it is the highest value that an int or the 
 //intValue of an Integer can have


public static final int MIN_VALUE
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[985]Integer Min value
By parisjackson { at } yahoo { dot } com on 2004/10/02 11:46:37  Rate
int i = Integer.MIN_VALUE; 
 System.out.println (  i  ) ; 
  
  
 //outputs the line 
 // -2147483648 
 // 
 //MIN_VALUE is a constant - it is the lowest value that an int or the 
 //intValue of an Integer can have


public static int numberOfLeadingZeros(int i)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static int numberOfTrailingZeros(int i)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static int parseInt(String s)
                    throws NumberFormatException
See Also:
parseInt(java.lang.String, int)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[307]parseInt actually throws 2 exceptions
By Anonymous on 2004/09/16 00:05:31  Rate
// NOTE: parseInt actually throws 2 exceptions,  
 // NullPointerException & NumberFormatException 
 try 
  {  
     String s; 
     int i = Integer.parseInt ( s ) ; 
  }  
 catch  ( NullPointerException npe )   {  
     //some error handling 
  }  
 catch  ( NumberFormatException nfe )   {  
     //some error handling 
  } 


public static int parseInt(String s,
                           int radix)
                    throws NumberFormatException
See Also:
Character.MAX_RADIX, Character.MIN_RADIX, Character.digit(char, int)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[1458]Test ability to convert String to HEX
By rufustopheles on 2005/06/23 15:36:07  Rate
// How about test ability to convert String to HEX 
 //  NOTE: parseInt throws 2 exceptions,  
 //  NullPointerException & NumberFormatException 
  
  
 try 
  {  
    // attempt convert to hex 
    String s = "1234567890" 
    int i = Integer.parseInt ( s,16 ) ; 
    System.out.print ( "OK. Hex Value of: " + s + " = " + i ) ; 
  }  
 catch  ( NullPointerException npe )   {  
    // add some error handling here 
  }  
 catch  ( NumberFormatException nfe )   {  
    // add some error handling here 
  } 


public static int reverse(int i)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static int reverseBytes(int i)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static int rotateLeft(int i,
                             int distance)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static int rotateRight(int i,
                              int distance)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public short shortValue()
See Also:
Number
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static int signum(int i)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static final int SIZE
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static String toBinaryString(int i)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[976]Convert an integer to binary
By parisjackson { at } yahoo { dot } com on 2004/12/01 00:26:47  Rate
int i = 15; 
 String s = Integer.toBinaryString (  i  ) ; 
 System.out.println (  s  ) ; 
 //outputs the line: 
 // 1111 
 


public static String toHexString(int i)
See Also:
String.toUpperCase()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[977]Integer to Hex
By parisjackson { at } yahoo { dot } com on 2004/10/02 11:36:04  Rate
int i = 15; 
 String s = Integer.toHexString (  i  ) ; 
 System.out.println (  s  ) ; 
 //outputs the line: 
 // f


[1535]byte to hex
By Anonymous on 2005/09/13 07:18:00  Rate
public static String byte_to_hex_string ( byte b )  
  {  
   String retval = ""; 
   int i =  ( int )  ( b ) ; 
   String s = Integer.toHexString ( i | 0x100 ) ; 
   if  ( s.length (  )  == 3 )  
    {  
     retval = s.substring ( 1 ) ; 
    }  
   else 
    {  
     retval = s.substring ( 6 ) ; 
    }  
   return retval; 
  } 


public static String toOctalString(int i)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[978]Integer to Octal
By parisjackson { at } yahoo { dot } com on 2004/10/02 11:36:25  Rate
int i = 15; 
 String s = Integer.toOctalString (  i  ) ; 
 System.out.println (  s  ) ; 
 //outputs the line: 
 // 17


public String toString()
See Also:
Object, toString(int)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[979]_
By parisjackson { at } yahoo { dot } com on 2004/10/02 11:37:12  Rate
Integer i1 = new Integer (  100  ) ; 
 String s = i1.toString (  ) ; 
 System.out.println (  s  ) ; 
 //outputs the line: 
 // 100


public static String toString(int i)
See Also:
toString(int, int)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[980]_
By parisjackson { at } yahoo { dot } com on 2004/10/02 11:38:29  Rate
System.out.println (  Integer.toString (  50  )   ) ; 
 //outputs the line: 
 // 50


public static String toString(int i,
                              int radix)
See Also:
Character.MIN_RADIX, Character.MAX_RADIX, String.toUpperCase()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[981]Integer to binary, octal, hex
By parisjackson { at } yahoo { dot } com on 2004/10/02 11:39:30  Rate
System.out.println (  Integer.toString (  15, 2  )   ) ; 
 System.out.println (  Integer.toString (  15, 8  )   ) ; 
 System.out.println (  Integer.toString (  15, 16  )   ) ; 
 //outputs the lines: 
 // 1111 
 // 17 
 // f 
 


public static final Class<Integer> TYPE
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static Integer valueOf(int i)
See Also:
Integer(int)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static Integer valueOf(String s)
                       throws NumberFormatException
See Also:
parseInt(java.lang.String)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[982]_
By parisjackson { at } yahoo { dot } com on 2004/10/02 11:40:54  Rate
String s = "14"; 
 Integer i1 = Integer.valueOf (  s  ) ; 
 System.out.println (  i1.toString (  )   ) ; 
 //outputs the line 
 // 14


public static Integer valueOf(String s,
                              int radix)
                       throws NumberFormatException
See Also:
parseInt(java.lang.String, int)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[983]Binary, octal, hex to decimal
By parisjackson { at } yahoo { dot } com on 2004/10/02 11:41:52  Rate
String s1 = "1110"; 
 String s2 = "16"; 
 String s3 = "e"; 
 Integer i1 = Integer.valueOf (  s1, 2  ) ; 
 Integer i2 = Integer.valueOf (  s2, 8  ) ; 
 Integer i3 = Integer.valueOf (  s3, 16  ) ; 
 System.out.println (  i1.toString (  )   ) ; 
 System.out.println (  i2.toString (  )   ) ; 
 System.out.println (  i3.toString (  )   ) ; 
  
  
 //outputs the lines 
 // 14 
 // 14 
 // 14

Popular Tags