0% found this document useful (0 votes)
19 views1 page

Java BuiltIn Methods

The document provides a list of useful built-in Java methods categorized into three sections: Math class methods, String class methods, and Arrays utility methods. It includes examples for each method, demonstrating their functionality such as calculating absolute values, string manipulations, and array operations. This serves as a quick reference for Java developers to utilize these methods effectively.

Uploaded by

22p61a05g7
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)
19 views1 page

Java BuiltIn Methods

The document provides a list of useful built-in Java methods categorized into three sections: Math class methods, String class methods, and Arrays utility methods. It includes examples for each method, demonstrating their functionality such as calculating absolute values, string manipulations, and array operations. This serves as a quick reference for Java developers to utilize these methods effectively.

Uploaded by

22p61a05g7
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/ 1

Useful Java Built-in Methods

1. Math Class Methods

- Math.abs(x): Absolute value. Example: Math.abs(-5) => 5


- Math.max(a, b): Larger of two values. Example: Math.max(3, 8) => 8
- Math.min(a, b): Smaller of two values. Example: Math.min(3, 8) => 3
- Math.pow(x, y): Power. Example: Math.pow(2, 3) => 8.0
- Math.sqrt(x): Square root. Example: Math.sqrt(9) => 3.0
- Math.cbrt(x): Cube root. Example: Math.cbrt(27) => 3.0
- Math.round(x): Rounds to nearest int. Example: Math.round(2.6) => 3
- Math.ceil(x): Rounds up. Example: Math.ceil(2.1) => 3.0
- Math.floor(x): Rounds down. Example: Math.floor(2.9) => 2.0
- Math.random(): Random number [0.0, 1.0)

2. String Class Methods

- length(): Length of string. Example: "hello".length() => 5


- charAt(i): Char at index i. Example: "hello".charAt(1) => 'e'
- substring(i, j): Part of string i to j-1. Example: "hello".substring(1, 3) => "el"
- toLowerCase(): Convert to lower. Example: "HeLLo".toLowerCase() => "hello"
- toUpperCase(): Convert to upper. Example: "hello".toUpperCase() => "HELLO"
- equals(): Compare strings. Example: "a".equals("A") => false
- equalsIgnoreCase(): Case-insensitive compare. Example: "a".equalsIgnoreCase("A") => true
- contains(): Check if contains. Example: "abc".contains("b") => true
- replace(): Replace chars. Example: "apple".replace("p", "b") => "abble"

3. Arrays Utility Methods

- Arrays.sort(arr): Sort the array.


- Arrays.toString(arr): Convert array to string format.
- Arrays.copyOf(arr, n): Copy first n elements.

You might also like