Professional Documents
Culture Documents
Integer- int
Double- double
Float- float
Long- long
Byte- byte
Short- short
1
-1
0
Integer x = 5;
System.out.println(x.compareTo(3)); //prints 1
System.out.println(x.compareTo(5));
//prints 0
System.out.println(x.compareTo(8)); // prints -1
3. To check equality:
boolean equals(Object o)
Integer x = 5;
Integer y = 10;
Integer z =5;
Short a = 5;
System.out.println(x.equals(y));
//false
System.out.println(x.equals(z)); //true
System.out.println(x.equals(a)); //false
If objects are of same type and have same value, returns true
Else false.
4. valueOf int/string as object:
static Integer valueOf(int i)
static Integer valueOf(String s)
Integer x =Integer.valueOf(9); //9
Double c = Double.valueOf(5);//5.0
Float a = Float.valueOf("80");
//80.0
//5 as a string
7. Other methods:
All returns primitive data type, has parameter of primitive data type
Math.sqrt(x), Math.pow(x,y), Math.min, Math.max(), Math.abs(),
Math.ceil(x), Math.floor(x), Math.sin(x), Math.asin(x)
Math.random()== random no between 0.0 to 1.0
String
Or
char[] helloArray = { 'h', 'e', 'l', 'l', 'o', '.'};
String helloString = new String(helloArray);
1. Length=
greeting.length() = 12
2. Concate:
Add strings
Eg: string1= string1 + string2
Str= hel + lo
3. char charAt(int index)
s=hellogram;
eg: char ch= s.charAt(5)
//g
Gives outout
Welcome
to-Tutorialspoint.com
9. Substring:
public String substring(int beginIndex)
public String substring(int beginIndex, int endIndex)
String Str = new String("Welcome to Tutorialspoint.com");
System.out.println(Str.substring(10) );// Tutorialspoint.com
System.out.println(Str.substring(10, 15) ); //Tuto
11. Case
public String toLowerCase()
public String toUpperCase()
Strig str2= Str.toLowerCase()
14.Return string;
Public String method()
{
Str= hey;
Return str;
}
Array
length= myList.length
1. Passing array to function
public static void printArray(int[] array) {
3. Sort array
public static void sort(int[] a)
public static void sort(int[] a, int fromIndex, int toIndex)
4. Binary Search
public static int binarySearch(int[] a, int key)
public static int binarySearch(int[] a, int fromIndex, int toIndex, int key)
//returns true
7. Array tostring
public static String toString(int[] a)
int[] i1 = new int[] { 33, 12, 98 };
System.out.println("The string representation of array is:");
System.out.println(Arrays.toString(i1));
Output:
Arraylist
1.
2.
3.
4.
5.
6.
7.
8.
9.