Locale locale = new Locale("en", "US", "POSIX"); String variant = locale.getVariant(); System.out.println(variant); // Output: POSIX
Locale locale = new Locale("zh", "CN", "Hans"); String variant = locale.getVariant(); System.out.println(variant); // Output: HansIn this example, we create a Locale object representing Simplified Chinese language, China country and Hans variant, and use the getVariant() method to retrieve the variant code. This method is included in the java.util package library.