0% found this document useful (0 votes)
1 views3 pages

Java Predefined Methods Guide

The document provides a comprehensive guide to Java's predefined methods, including examples and outputs for String, Math, Arrays, Integer, Double, Character methods, as well as Collections and Object/System methods. It covers various functionalities such as string manipulation, mathematical calculations, array operations, and collection handling. Each method is illustrated with sample code and corresponding output for clarity.

Uploaded by

i66922215
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)
1 views3 pages

Java Predefined Methods Guide

The document provides a comprehensive guide to Java's predefined methods, including examples and outputs for String, Math, Arrays, Integer, Double, Character methods, as well as Collections and Object/System methods. It covers various functionalities such as string manipulation, mathematical calculations, array operations, and collection handling. Each method is illustrated with sample code and corresponding output for clarity.

Uploaded by

i66922215
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

Java Predefined Methods Guide with Examples and

Outputs

String Methods
length() -> "Java".length() = 4

charAt()
String s="Java";
[Link](1);
Output: a

substring()
"Java".substring(1);
Output: ava

equals()
"Java".equals("Java");
Output: true

contains()
"Java".contains("av");
Output: true

indexOf('a') -> 1
lastIndexOf('a') -> 3
toUpperCase() -> JAVA
toLowerCase() -> java
replace('a','o') -> Jovo
startsWith("Ja") -> true
endsWith("va") -> true
trim() -> removes leading/trailing spaces

Math Methods
[Link](-10) -> 10
[Link](5,9) -> 9
[Link](5,9) -> 5
[Link](25) -> 5.0
[Link](2,3) -> 8.0
[Link](4.2) -> 5.0
[Link](4.9) -> 4.0
[Link](4.6) -> 5
[Link]() -> value between 0 and 1

Arrays Class
int[] arr={0,5,3,2,8,1};

[Link](arr);
Output: [0, 1, 2, 3, 5, 8]
[Link](arr,5);
Output: 4

[Link](a,b);
Output: true

[Link](a,10);
Output: [10,10]

[Link](arr,3);
Output: [0,1,2]

[Link](arr);
Output: [0, 1, 2, 3, 5, 8]

Integer, Double and Character Methods


[Link]("123") -> 123
[Link]("100") -> 100
[Link](50) -> "50"

[Link]("12.5") -> 12.5


[Link]("45.6") -> 45.6

[Link]('5') -> true


[Link]('A') -> true
[Link]('A') -> true
[Link]('a') -> true
[Link]('b') -> B
[Link]('B') -> b

Collections
ArrayList:
add(), get(), set(), remove(), contains(),
indexOf(), size(), isEmpty(), clear()

HashSet:
add(), remove(), contains(), size(),
isEmpty(), clear()

HashMap:
put(), get(), remove(),
containsKey(), containsValue(),
keySet(), values(), size(), clear()

Object and System Methods


Object:
toString()
equals()
hashCode()
getClass()

System:
currentTimeMillis()
nanoTime()
gc()
exit(0)

You might also like