Saturday, September 6, 2025
HomeLanguagesJavaWeekFields hashCode() method in Java with Examples

WeekFields hashCode() method in Java with Examples

The hashCode() method of WeekFields class is used to return the hash code for this WeekFields.It returns an integer value which is the hashCode value for this instance of the ValueRange.

Syntax:

public int hashCode()

Parameters: This method accepts nothing.

Return value: This method returns integer value which is the hashCode value.

Below programs illustrate the WeekFields.hashCode() method:
Program 1:




// Java program to demonstrate
// WeekFields.hashCode() method
  
import java.time.DayOfWeek;
import java.time.temporal.WeekFields;
  
public class GFG {
    public static void main(String[] args)
    {
  
        // create WeekFields
        WeekFields weekFields
            = WeekFields.of(DayOfWeek.MONDAY, 1);
  
        // apply hashCode()
        int hashCode = weekFields.hashCode();
  
        // print results
        System.out.println("Hash Code:"
                           + hashCode);
    }
}


Output:

Hash Code:1

Program 2:




// Java program to demonstrate
// WeekFields.hashCode() method
  
import java.time.DayOfWeek;
import java.time.temporal.WeekFields;
import java.util.Locale;
  
public class GFG {
    public static void main(String[] args)
    {
  
        Locale locale = new Locale("EN", "US");
  
        // create WeekFields
        WeekFields weekFields
            = WeekFields.of(locale);
  
        // apply hashCode()
        int hashCode = weekFields.hashCode();
  
        // print results
        System.out.println("Hash Code:"
                           + hashCode);
    }
}


Output:

Hash Code:43

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

RELATED ARTICLES

Most Popular

Dominic
32270 POSTS0 COMMENTS
Milvus
82 POSTS0 COMMENTS
Nango Kala
6639 POSTS0 COMMENTS
Nicole Veronica
11803 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11869 POSTS0 COMMENTS
Shaida Kate Naidoo
6752 POSTS0 COMMENTS
Ted Musemwa
7029 POSTS0 COMMENTS
Thapelo Manthata
6705 POSTS0 COMMENTS
Umr Jansen
6721 POSTS0 COMMENTS