Example usage for java.util Locale US

List of usage examples for java.util Locale US

Introduction

In this page you can find the example usage for java.util Locale US.

Prototype

Locale US

To view the source code for java.util Locale US.

Click Source Link

Document

Useful constant for country.

Usage

From source file:MainClass.java

public static void main(String args[]) throws Exception {
    Locale defaultLocale = Locale.getDefault();
    System.out.println(defaultLocale.getDisplayVariant());
    System.out.println(defaultLocale.getDisplayVariant(Locale.US));
    System.out.println((new Locale("en", "US", "WIN_TX_Austin")).getDisplayVariant());
}

From source file:Main.java

public static void main(String[] args) {
    ResourceBundle bundle = ResourceBundle.getBundle("hello", Locale.US);
    Enumeration<String> keys = bundle.getKeys();
    ArrayList<String> temp = new ArrayList<String>();

    for (Enumeration<String> e = keys; keys.hasMoreElements();) {
        String key = e.nextElement();
        if (key.startsWith("java2s")) {
            temp.add(key);//  ww  w.  j  ava 2s  .com
        }
    }

    String[] result = new String[temp.size()];

    for (int i = 0; i < temp.size(); i++) {
        result[i] = bundle.getString(temp.get(i));
    }
    System.out.println(Arrays.toString(result));
}

From source file:Main.java

public static void main(String[] args) {

    String s = "java2s.com 1 + 1 = 2.0 true ";
    Float f = 1.2385f;//from   w  w w.  java2s .  c om
    s = s + f;

    Scanner scanner = new Scanner(s);

    scanner.useLocale(Locale.US);

    while (scanner.hasNext()) {
        scanner.next();
        if (scanner.hasNextFloat()) {
            System.out.println("Found :" + scanner.nextFloat());
        }
    }

    scanner.close();
}

From source file:Main.java

public static void main(String[] args) {

    String s = "java2s.com 3.12345f";

    Scanner scanner = new Scanner(s);

    // assign locale as US to recognize float numbers in a string
    scanner.useLocale(Locale.US);

    while (scanner.hasNext()) {
        // check if the scanner's next token is a float
        System.out.println(scanner.hasNextFloat());
        System.out.println(scanner.next());
    }//w  ww  .  j  ava 2 s. co m
    scanner.close();
}

From source file:Main.java

public static void main(String[] args) {

    String s = "java2s.com 1 + 1 = 2.0 1.3985";

    Scanner scanner = new Scanner(s);

    // assign locale as US to recognize double numbers in a string
    scanner.useLocale(Locale.US);

    while (scanner.hasNext()) {
        // check if the scanner's next token is a double
        System.out.println(scanner.hasNextDouble());
        System.out.println(scanner.next());
    }//from  www.java2 s .  c  o  m
    scanner.close();
}

From source file:Main.java

public static void main(String[] args) {

    String s = "java2s.com 1 + 1 = 2.0 ";

    Scanner scanner = new Scanner(s);

    // use US locale in order to be able to identify shorts in a string
    scanner.useLocale(Locale.US);

    while (scanner.hasNext()) {
        // check if the scanner's next token is a short
        System.out.println(scanner.hasNextShort());

        System.out.println(scanner.next());
    }/* w w w  .  j  av a  2  s. co m*/

    scanner.close();
}

From source file:Main.java

public static void main(String[] args) {

    ResourceBundle.Control rbc = ResourceBundle.Control.getControl(Control.FORMAT_DEFAULT);

    ResourceBundle bundle = ResourceBundle.getBundle("hello", Locale.US, rbc);

    System.out.println(bundle.getString("hello"));

}

From source file:Main.java

public static void main(String[] argv) {
    NumberFormat numberFormat = NumberFormat.getInstance();
    numberFormat.setParseIntegerOnly(false);
    double usersNumber = 197912.29;

    numberFormat = NumberFormat.getNumberInstance(Locale.US);
    System.out.println("User's number (US): " + numberFormat.format(usersNumber));
    numberFormat = NumberFormat.getNumberInstance(Locale.GERMANY);
    System.out.println("User's number (GERMANY): " + numberFormat.format(usersNumber));
    numberFormat = NumberFormat.getNumberInstance();
    System.out.println("User's number (DEFAULT LOCALE): " + numberFormat.format(usersNumber));
}

From source file:DisplayNameOutput.java

public static void main(String[] argv) {

    Locale defaultLocale = Locale.getDefault();
    System.out.println(defaultLocale.getDisplayName());
    System.out.println(defaultLocale.getDisplayName(Locale.ITALIAN));
    System.out.println(defaultLocale.getDisplayName(Locale.US));
}

From source file:MainClass.java

public static void main(String args[]) throws Exception {
    Locale defaultLocale = Locale.getDefault();
    System.out.println(defaultLocale.getDisplayName());
    System.out.println(defaultLocale.getDisplayName(Locale.ITALIAN));
    System.out.println(defaultLocale.getDisplayName(Locale.US));
}