Skip to content
Related Articles

Related Articles

Improve Article

Level toString() method in Java with Examples

  • Last Updated : 14 Oct, 2019

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()

Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.




My Personal Notes arrow_drop_up
Recommended Articles
Page :