How to find the minimum value in the array list in Java – IT Blog
IT Blog
Boris IT Expert

How to find the minimum value in the array list in Java

Boris~November 3, 2020 /Array List

To find the minimum value in the array in Java, you should follow several steps. The basic idea to set the temporary variable that we will use to compare with each element in the list. By default, the minimum element should be the first element in the list. With the help of the loop, we will compare the current value of the temporary variable with the value of the current element in the loop. As the result, If the temporary variable is less than the value from the loop, we need to update the temporary variable’s value.

Search for a minimum element in the array list in Java example. Step-by-step implementation.

If you want to find the minimum element in the array list, you have to follow several steps:

//Creating the start point to compare it with the rest elements which is first element
        int temporaryVariable = intArray[0];
//Going through the array and comparing each element and return the minimum one
        for (int i = 0; i < arrayLength; i++) {
            if (temporaryVariable > intArray[i]) {

The full code example:

private void findMinimumOfArray() {
        //Created a new array of integers
  int[] intArray = new int[]{14, 5, 35, 44, 5, 17, 78, 13, 9, 21};

        //Get the length of the array
        int arrayLength = intArray.length;

        //Creating the start point to compare it with the rest elements which is first element
        int temporaryVariable = intArray[0];

        //Going through the array and comparing each element and return the minimum one
        for (int i = 0; i < arrayLength; i++) {
            if (temporaryVariable > intArray[i]) {
                //If next element smaller than the existing we are setting it as a smallest element
                temporaryVariable = intArray[i];
            }
        }

        //Showing in logs the smallest element
        Log.d("arrayList", "The minimum element is: " + temporaryVariable);

    }

The full code schema:

minimum element in array list java

In this article, you figured out the easiest way to find the minimum element in an array list in java.

Full code and more examples in my facebook group.

Useful links:

Leave Any Questions Related To This Article Below!