Saturday, October 25, 2025
HomeLanguagesJavaZoneOffset getAvailableZoneIds() method in Java with Examples

ZoneOffset getAvailableZoneIds() method in Java with Examples

The getAvailableZoneIds() method of the ZoneOffset class of java.time package is used to get the set of available zone IDs. This set includes all available region-based IDs. The ID can be passed to of(String) to create a ZoneId. The set of zone IDs can increase over time, although in a typical application the set of IDs is fixed.

Syntax:

public static Set getAvailableZoneIds()

Parameters: This method does not accepts any parameter.

Return value: This method returns Set which are a modifiable copy of the set of zone IDs.

Below examples illustrate the ZoneOffset.getAvailableZoneIds() method:

Example 1:




// Java code to illustrate getAvailableZoneIds() method
  
import java.time.*;
import java.util.*;
  
public class GFG {
    public static void main(String[] args)
    {
  
        // Get the ZoneOffset instance
        ZoneOffset zoneOffset
            = ZoneOffset.of("+05:30");
  
        // get available zones
        // using getAvailableZoneIds()
        Set<String> zoneIds
            = zoneOffset.getAvailableZoneIds();
  
        // print first record
        System.out.println("First ZoneId in list:"
                           + zoneIds.iterator().next());
    }
}


Output:

First ZoneId in list:Asia/Aden

Example 2:




// Java code to illustrate getAvailableZoneIds() method
  
import java.time.*;
import java.util.*;
  
public class GFG {
    public static void main(String[] args)
    {
  
        // Get the ZoneOffset instance
        ZoneOffset zoneOffset
            = ZoneOffset.of("Z");
  
        // get available zones
        // using getAvailableZoneIds()
        Set<String> zoneIds
            = zoneOffset.getAvailableZoneIds();
  
        // print first record
        System.out.println("First ZoneId in list:"
                           + zoneIds.iterator().next());
    }
}


Output:

First ZoneId in list:Asia/Aden

Reference: Oracle Doc

RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS