Thursday, February 19, 2026
HomeLanguagesJavaValueRange toString() method in Java with Examples

ValueRange toString() method in Java with Examples

The toString() method of ValueRange class is used to return this ValueRange as a String in format ‘{min}/{largestMin} – {smallestMax}/{max}’, where the largestMin or smallestMax sections may be omitted, together with associated slash, if they are the same as the min or max.

Syntax:

public String toString()

Parameters: This method accepts nothing.

Return value: This method returns a string representation of this range, not null.

Below programs illustrate the ValueRange.toString() method:
Program 1:




// Java program to demonstrate
// ValueRange.toString() method
  
import java.time.LocalDateTime;
import java.time.temporal.ChronoField;
import java.time.temporal.ValueRange;
  
public class GFG {
    public static void main(String[] args)
    {
  
        // create LocalDateTime
        LocalDateTime l1
            = LocalDateTime
                  .parse("2018-12-06T19:21:12");
  
        // Get ValueRange object
        ValueRange vR
            = l1.range(ChronoField.DAY_OF_MONTH);
  
        // print results using toString()
        System.out.println("ValueRange: "
                           + vR.toString());
    }
}


Output:

ValueRange: 1 - 31

Program 2:




// Java program to demonstrate
// ValueRange.toString() method
  
import java.time.temporal.ValueRange;
  
public class GFG {
    public static void main(String[] args)
    {
  
        // create ValueRange object
        ValueRange vRange = ValueRange.of(1111, 66666);
  
        // print results using toString()
        System.out.println("ValueRange: "
                           + vRange.toString());
    }
}


Output:

ValueRange: 1111 - 66666

References: https://docs.oracle.com/javase/10/docs/api/java/time/temporal/ValueRange.html#toString()

RELATED ARTICLES

Most Popular

Dominic
32506 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6882 POSTS0 COMMENTS
Nicole Veronica
12005 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12099 POSTS0 COMMENTS
Shaida Kate Naidoo
7011 POSTS0 COMMENTS
Ted Musemwa
7255 POSTS0 COMMENTS
Thapelo Manthata
6967 POSTS0 COMMENTS
Umr Jansen
6956 POSTS0 COMMENTS