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:Main.java

public static void main(String[] args) {

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

    Scanner scanner = new Scanner(s);

    System.out.println(scanner.nextLine());

    // change the locale of this scanner
    scanner.useLocale(Locale.US);

    // change the radix of this scanner
    scanner.useRadix(30);/*from  ww w  . j a  va2s . co  m*/

    // reset and check the values for radix and locale, which are the default
    scanner.reset();
    System.out.println(scanner.radix());
    System.out.println(scanner.locale());

    scanner.close();
}

From source file:Main.java

public static void main(String[] args) {

    String s = "java2s.com ";
    Long l = 1234567890987654L;/*from w w  w .  j  a v a  2  s. c om*/
    s = s + l;

    Scanner scanner = new Scanner(s);

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

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

        System.out.println(scanner.next());
    }
    scanner.close();
}

From source file:Main.java

public static void main(String[] args) {

    String s = "java2s.com ";
    Long l = 1234567890987654L;//from  w w  w  .j  ava 2  s .co  m
    s = s + l;

    Scanner scanner = new Scanner(s);

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

    while (scanner.hasNext()) {
        // check if the scanner's next token is a long with radix 4
        System.out.println(scanner.hasNextLong(4));

        System.out.println(scanner.next());
    }
    scanner.close();
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    String inputText = "Nov 10,2015";

    TimeZone utc = TimeZone.getTimeZone("UTC");

    SimpleDateFormat inputFormat = new SimpleDateFormat("MMM d,yyyy", Locale.US);
    inputFormat.setTimeZone(utc);//w ww .ja  v  a  2s.c o m

    SimpleDateFormat outputFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.US);
    outputFormat.setTimeZone(utc);

    Date parsed = inputFormat.parse(inputText);
    String outputText = outputFormat.format(parsed);

    System.out.println(outputText);
}

From source file:Main.java

public static void main(String[] args) {

    ClassLoader cl = ClassLoader.getSystemClassLoader();

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

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

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

}

From source file:MainClass.java

public static void main(String args[]) throws Exception {
    NumberFormat numberFormat = NumberFormat.getInstance();
    numberFormat.setParseIntegerOnly(false);
    double usersNumber = 1976.0826;

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

}

From source file:MessageFormatReuse.java

public static void main(String args[]) {
    String pattern = "{0}K was deleted on {1}.";
    MessageFormat formatter = new MessageFormat(pattern);

    Double kb = new Double(3.5);
    Date today = new Date();
    Object[] arguments = { kb, today };

    formatter.setLocale(Locale.US);
    System.out.println(formatter.format(arguments));
}

From source file:MainClass.java

public static void main(String[] argv) {
    String pattern = "{0}K was deleted on {1}.";
    MessageFormat formatter = new MessageFormat(pattern);

    Double kb = new Double(3.5);
    Date today = new Date();
    Object[] arguments = { kb, today };

    formatter.setLocale(Locale.US);
    System.out.println(formatter.format(arguments));

    formatter.setLocale(Locale.FRANCE);
    System.out.println(formatter.format(arguments));

    pattern = "On {1}, {0}K was deleted.";
    formatter.applyPattern(pattern);/*from  www  .  j ava  2  s  .  co  m*/
    System.out.println(formatter.format(arguments));

    formatter.setLocale(Locale.US);
    System.out.println(formatter.format(arguments));
}

From source file:Main.java

public static void main(String[] args) {
    Currency currency = Currency.getInstance(Locale.JAPAN);
    System.out.println("Currency.getSymbol() = " + currency.getSymbol());

    currency = Currency.getInstance(Locale.UK);
    System.out.println("Currency.getSymbol() = " + currency.getSymbol());

    currency = Currency.getInstance(Locale.US);
    System.out.println("Currency.getSymbol() = " + currency.getSymbol());

    currency = Currency.getInstance(new Locale("in", "ID"));
    System.out.println("Currency.getSymbol() = " + currency.getSymbol());
}

From source file:Main.java

public static void main(String[] args) {
    List<String> fruits = new ArrayList<String>();
    fruits.add("A");
    fruits.add("");
    fruits.add("C");
    fruits.add("D");
    fruits.add("A");

    Collator collator = Collator.getInstance(Locale.US);

    Collections.sort(fruits, collator);

    for (int i = 0; i < fruits.size(); i++) {
        String fruit = fruits.get(i);

        System.out.println("Fruit = " + fruit);
    }//ww w  . j a va 2  s .  c o m
}