Java Built-In Methods

In this Java article we want to learn about Java Built-In Methods, Java is popular programming language that is widely used for developing enterprise level applications, web applications and mobile applications. in this article we want to talk about some commonly Java built-in methods and how they can be used in our programs.

 

 

There are different Java Methods that you use.

String Methods This is used for working with strings, which are sequences of characters.
Math Methods This is used for working math operations
Array Methods This is used for working with arrays

 

 

 

So now let’s start from Java String Methods.

 

Java String Methods

Java provides different built-in methods for working with strings, which are sequences of characters. these are some commonly used string methods:

 

  • length()
    length() method returns the length of string. this is an example:

 

 

This will be the result

Java Built-In Methods
Java Built-In Methods

 

 

  • charAt()
    charAt() method returns the character at specific index in a string. if you run this code it will return G.

 

 

  • indexOf()
    indexOf() method returns the index of the first occurrence of specified character or substring in a string, it will return 12.

 

 

  • indexOf()
    indexOf() method returns the index of the first occurrence of specified character or substring in string. 

 

 

This will be the result

Java Built-In Methods
Java Built-In Methods

 

 

Java Math Methods

Java also provides different builtin methods for performing mathematical operations. these are some commonly used math methods:

 

  • abs()
    abs() method returns the absolute value of a number like this.

 

 

This ill be the result

Java Abs Method
Java Abs Method

 

 

  • ceil()
    ceil() method rounds a number up to the nearest integer like this, it will return 6.0

 

 

  • floor()
    floor() method rounds a number down to the nearest integer like this, it will return 4.0

 

 

  • pow()
    pow() method raises a number to specified power, you can use it like this.

 

 

This will be the result

Java Pow Method
Java Pow Method

 

 

 

Java Array Methods

Arrays are fundamental data structure in Java, and Java provides different builtin methods for working with arrays. these are some commonly used array methods:

 

 

  • length
    length property of an array returns the number of elements in the array, it will return 5. 

 

 

  • sort()
    sort() method sorts the elements of an array in ascending order.

 

 

  • binarySearch()
    binarySearch() method searches for a specified element in an array using binary search algorithm, you can use it like this.

 

 

 

Learn More

Leave a Comment