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

Java Builtin Functions Examples

The document provides an overview of various built-in Java functions categorized into String, Math, Wrapper, Arrays, Collections, System, Object classes, and a Trim method, along with examples for each. It demonstrates methods such as string manipulation, mathematical operations, array sorting, collection handling, and object methods. Each section includes code snippets illustrating the usage of these functions.
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)
11 views3 pages

Java Builtin Functions Examples

The document provides an overview of various built-in Java functions categorized into String, Math, Wrapper, Arrays, Collections, System, Object classes, and a Trim method, along with examples for each. It demonstrates methods such as string manipulation, mathematical operations, array sorting, collection handling, and object methods. Each section includes code snippets illustrating the usage of these functions.
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 Built-in Functions with Examples

■ String Class Methods


String str = " Hello Java ";
[Link]([Link]()); // 12
[Link]([Link](1)); // 'H'
[Link]([Link](1, 6)); // "Hello"
[Link]([Link]()); // " hello java "
[Link]([Link]()); // " HELLO JAVA "
[Link]([Link]()); // "Hello Java"
[Link]([Link]("Hello")); // false
[Link]([Link]("Java")); // true
[Link]([Link]("Java", "World")); // " Hello World "

■ Math Class Methods


[Link]([Link](-10)); // 10
[Link]([Link](5, 9)); // 9
[Link]([Link](5, 9)); // 5
[Link]([Link](2, 3)); // 8.0
[Link]([Link](25)); // 5.0
[Link]([Link](4.3)); // 5.0
[Link]([Link](4.9)); // 4.0
[Link]([Link](4.6)); // 5
[Link]([Link]()); // random 0.0–1.0

■ Wrapper Class Methods


int num = [Link]("123"); // String → int
double d = [Link]("3.14"); // String → double
String s = [Link](99); // int → String
String s2 = [Link](456); // int → String

[Link](num + 1); // 124


[Link](d + 1); // 4.14
[Link](s + " is a string"); // "99 is a string"
[Link](s2); // "456"

char c = 'A';
[Link]([Link](c)); // false
[Link]([Link](c)); // true

■ Arrays Utility Methods


int[] arr = {5, 3, 8, 1};

[Link](arr);
[Link]([Link](arr)); // [1, 3, 5, 8]

int index = [Link](arr, 5);


[Link]("Index of 5: " + index); // 2

int[] copy = [Link](arr, 6);


[Link]([Link](copy)); // [1, 3, 5, 8, 0, 0]

[Link](copy, 7);
[Link]([Link](copy)); // [7, 7, 7, 7, 7, 7]

■ Collections Utility Methods


List<Integer> list = new ArrayList<>([Link](5, 2, 9, 1));

[Link](list);
[Link](list); // [1, 2, 5, 9]

[Link](list);
[Link](list); // [9, 5, 2, 1]

[Link]([Link](list)); // 9
[Link]([Link](list)); // 1

[Link](list);
[Link]("Shuffled: " + list);

■ System Class Methods


long time = [Link]();
[Link]("Current time (ms): " + time);

String javaVersion = [Link]("[Link]");


[Link]("Java Version: " + javaVersion);

int[] src = {1, 2, 3};


int[] dest = new int[3];
[Link](src, 0, dest, 0, 3);
for (int x : dest) {
[Link](x + " "); // 1 2 3
}

■ Object Class Methods


class Person {
String name;
Person(String name) { [Link] = name; }

@Override
public String toString() {
return "Person: " + name;
}
}

Person p1 = new Person("Alice");


Person p2 = new Person("Alice");
[Link]([Link]()); // Person: Alice
[Link]([Link](p2)); // false (different objects)
[Link]([Link]()); // unique number
[Link]([Link]()); // class Person

■ Trim Method
String str = " Hello Java ";
[Link]("Before trim: [" + str + "]");
[Link]("After trim : [" + [Link]() + "]");

String str2 = " ";


if ([Link]().isEmpty()) {
[Link]("String is empty after trim.");
}

You might also like