0% found this document useful (0 votes)
14 views4 pages

Java Builtin Methods JavaLang

The document is a handbook detailing built-in Java methods across various classes including Object, String, Math, and Wrapper classes. It provides method names, descriptions, and examples for each method, illustrating their usage. This serves as a reference for developers to understand and utilize Java's built-in functionalities effectively.

Uploaded by

mohammadsoyal945
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views4 pages

Java Builtin Methods JavaLang

The document is a handbook detailing built-in Java methods across various classes including Object, String, Math, and Wrapper classes. It provides method names, descriptions, and examples for each method, illustrating their usage. This serves as a reference for developers to understand and utilize Java's built-in functionalities effectively.

Uploaded by

mohammadsoyal945
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

■ Java Built-in Methods Handbook

Chapter 1: java.lang Package

1. Object Class Methods


Method Description Example

class Car {String brand="BMW"; public String toString(){return brand;


toString() Returns string representation of object. Car c=new Car(); System.out.println(c.toString());

String s1="Java"; String s2="Java";


equals(Object obj) Compares two objects for equality. System.out.println(s1.equals(s2)); // true

String s="Java";
hashCode() Returns integer hash code value for object. System.out.println(s.hashCode());

String s="Java";
getClass() Returns runtime class of object. System.out.println(s.getClass());

class A implements Cloneable {int x=10;}


clone() Creates and returns copy of object. A a=new A(); A b=(A)a.clone();

finalize() Called before object is destroyed by GC. protected void finalize(){System.out.println("Object destroyed");}
2. String Class Methods
Method Description Example

length() Returns string length. String s="Hello"; System.out.println(s.length()); //5

charAt() Returns char at index. String s="Java"; System.out.println(s.charAt(1)); //a

substring() Returns part of string. String s="Programming"; System.out.println(s.substring(0,4)); //Prog

equals() Checks string equality. String s1="Java", s2="Java"; System.out.println(s1.equals(s2)); //true

equalsIgnoreCase() Ignores case while comparing. String s1="java", s2="JAVA"; System.out.println(s1.equalsIgnoreCas

compareTo() Compares two strings lexicographically. System.out.println("abc".compareTo("abd")); // -1

toUpperCase() Converts to upper case. System.out.println("java".toUpperCase()); //JAVA

toLowerCase() Converts to lower case. System.out.println("JAVA".toLowerCase()); //java

trim() Removes leading/trailing spaces. System.out.println(" hi ".trim()); //hi

replace() Replaces characters. System.out.println("Java".replace('a','o')); //Jovo

split() Splits string into array. String[] arr="a,b,c".split(",");

contains() Checks substring present. System.out.println("Hello Java".contains("Java")); //true

startsWith() Checks prefix. System.out.println("Java".startsWith("Ja")); //true

endsWith() Checks suffix. System.out.println("Java".endsWith("va")); //true

isEmpty() Checks empty string. System.out.println("".isEmpty()); //true


3. Math Class Methods
Method Description Example

abs() Returns absolute value. System.out.println(Math.abs(-10)); //10

max() Returns max of 2 numbers. System.out.println(Math.max(5,9)); //9

min() Returns min of 2 numbers. System.out.println(Math.min(5,9)); //5

sqrt() Square root. System.out.println(Math.sqrt(16)); //4.0

pow() Power calculation. System.out.println(Math.pow(2,3)); //8.0

random() Returns random [0,1). System.out.println(Math.random());

round() Rounds to nearest int. System.out.println(Math.round(2.6)); //3

ceil() Ceil value. System.out.println(Math.ceil(2.3)); //3.0

floor() Floor value. System.out.println(Math.floor(2.9)); //2.0


4. Wrapper Classes Methods
Method Description Example

parseInt() Converts String to int. int n=Integer.parseInt("100");

parseDouble() Converts String to double. double d=Double.parseDouble("10.5");

valueOf() Returns wrapper object. Integer n=Integer.valueOf("50");

toString() Converts to String. Integer n=100; System.out.println(n.toString());

compareTo() Compares two values. Integer n1=5,n2=10; System.out.println(n1.compareTo(n2)); //-1

isDigit() Checks if char is digit. System.out.println(Character.isDigit('5')); //true

isLetter() Checks if char is letter. System.out.println(Character.isLetter('a')); //true

isWhitespace() Checks if whitespace. System.out.println(Character.isWhitespace(' ')); //true

You might also like