Monday, November 24, 2025
HomeLanguagesJavaLevel toString() method in Java with Examples

Level toString() method in Java with Examples

The toString() method of java.util.logging.Level is used to get the string value which represents this Level.This method returns a string representation of this Level.

Syntax:

public String toString()

Parameters: This method accepts nothing.

Return: This method returns a string representation of this Level..

Below programs illustrate toString() method:
Program 1:




// Java program to illustrate toString() method
  
import java.util.logging.Level;
import java.util.logging.Logger;
  
public class GFG {
  
    public static void main(String[] args)
    {
  
        // Create a Logger
        Logger logger
            = Logger.getLogger(
                        String.class.getName())
                  .getParent();
  
        // Get level of logger
        Level level
            = logger.getLevel();
  
        // get string value of level
        String val = level.toString();
  
        // print result
        System.out.println("toString = "
                           + val);
    }
}


Output:

toString = INFO

Program 2:




// Java program to illustrate toString() method
  
import java.util.logging.Level;
  
public class GFG {
  
    public static void main(String[] args)
    {
  
        // Get level of logger
        Level level
            = Level.parse("SEVERE");
  
        // get string representation
        String value = level.toString();
  
        // print result
        System.out.println("toString = "
                           + value);
    }
}


Output:

toString = SEVERE

References: https://docs.oracle.com/javase/10/docs/api/java/util/logging/Level.html#toString()

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

1 COMMENT

Most Popular

Dominic
32410 POSTS0 COMMENTS
Milvus
97 POSTS0 COMMENTS
Nango Kala
6785 POSTS0 COMMENTS
Nicole Veronica
11932 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12000 POSTS0 COMMENTS
Shaida Kate Naidoo
6909 POSTS0 COMMENTS
Ted Musemwa
7168 POSTS0 COMMENTS
Thapelo Manthata
6865 POSTS0 COMMENTS
Umr Jansen
6852 POSTS0 COMMENTS