ServiceLoader iterator() in Java

iterator(): This method is available in java.util.ServiceLoader class of Java.

Syntax:

Iterator<String> java.util.ServiceLoader.iterator()

This method returns an iterator to lazily load and instantiate the available providers of this loader's service.

Parameters: NA

Returns: An iterator that lazily loads providers for this loader'sservice.

Exceptions: NA

Approach

Java

import java.util.Iterator;
import java.util.ServiceLoader;

public class ServiceLoaderiterator {
    public static void main(String[] args) {

        ServiceLoader<String> serviceLoader =
ServiceLoader.load(String.class);

        Iterator<String> iterator = serviceLoader.iterator();

        System.out.println(iterator);

    }

}

Output:

java.util.ServiceLoader$3@3cd1f1c8


No comments:

Post a Comment