Saturday, January 11, 2025
Google search engine
HomeLanguagesJavaResolverStyle values() method in Java with Examples

ResolverStyle values() method in Java with Examples

The values() method of ResolverStyle enum is used to an array containing the units of this ResolverStyle, in the order, they are declared. 

Syntax:

public static ResolverStyle[] values()

Parameters: This method accepts nothing. 

Return value: This method returns an array containing the constants of this enum type, in the order, they are declared. Below programs illustrate the ResolverStyle.values() method:

Program 1: 

Java




// Java program to demonstrate
// ResolverStyle.values() method
 
import java.time.format.ResolverStyle;
 
public class GFG {
   
    public static void main(String[] args)
    {
 
        // Get ResolverStyle instance
        ResolverStyle resolverStyle
            = ResolverStyle.valueOf(" SMART & quot;);
 
        // Get the constants using values()
        ResolverStyle[] array = resolverStyle.values();
 
        // Print the values
        for (int i = 0; i & lt; array.length; i++)
            System.out.println(array[i]);
    }
}


Output:

STRICT
SMART
LENIENT

Program 2: 

Java




// Java program to demonstrate
// ResolverStyle.values() method
 
import java.time.format.ResolverStyle;
 
public class GFG {
   
    public static void main(String[] args)
    {
 
        // Get ResolverStyle instance
        ResolverStyle resolverStyle
            = ResolverStyle.valueOf(" LINIENT & quot;);
 
        // Get the constants using values()
        ResolverStyle[] array = resolverStyle.values();
 
        // Print the values
        System.out.println(" ResolverStyle length
                           : "
                           + array.length);
    }
}


Output:

ResolverStyle length: 3

Example:

Java




package abc;
 
import java.io.*;
import java.time.format.ResolverStyle;
import java.util.Scanner;
 
public class as {
    public static void main(String[] args)
    {
        Scanner scanner = new Scanner(System.in);
        System.out.print(
            "Enter a resolver style (smart, strict, lenient): ");
        String input = scanner.nextLine().toLowerCase();
        ResolverStyle style = null;
        switch (input) {
        case "smart":
            style = ResolverStyle.SMART;
            break;
        case "strict":
            style = ResolverStyle.STRICT;
            break;
        case "lenient":
            style = ResolverStyle.LENIENT;
            break;
        default:
            System.out.println("Invalid input.");
            System.exit(0);
        }
        System.out.println("Resolver Style: " + style);
    }
}


Output:

Enter a resolver style (smart, strict, lenient): strict
Resolver Style: STRICT

RELATED ARTICLES

Most Popular

Recent Comments