Create Java integer
In this chapter you will learn:
Create Integer using its constructors
Integer(int value)
creates an Integer object for the int value.Integer(String s)
creates an Integer object for the int value indicated bys
.
public class Main {
public static void main(String[] args) {
//from j a v a 2 s .c om
Integer integer1 = new Integer("1");
Integer integer2 = new Integer("2");
System.out.println(integer1);
System.out.println(integer2);
}
}
The output:
The following code creates Integer objects from int literal and string representation
public class Main {
public static void main(String[] args) {
Integer intObj1 = new Integer(10);
Integer intObj2 = new Integer("10");
System.out.println(intObj1);/*from j a va 2s . c o m*/
System.out.println(intObj2);
}
}
The output:
Next chapter...
What you will learn in the next chapter:
Home » Java Tutorial » Primitive Data Types