Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.util.Locale;

public class Main {
    public static Locale stringToLocale(String locString) {

        locString = locString != null ? locString.trim() : "";
        if (locString.equals(""))
            return new Locale("", "", "");
        int pos = locString.indexOf(95);
        if (pos == -1)
            return new Locale(locString, "", "");
        String language = locString.substring(0, pos);
        locString = locString.substring(pos + 1);
        pos = locString.indexOf(95);
        if (pos == -1) {
            return new Locale(language, locString, "");
        } else {
            String country = locString.substring(0, pos);
            locString = locString.substring(pos + 1);
            return new Locale(language, country, locString);
        }
    }
}