Created
November 21, 2013 18:15
-
-
Save joshskeen/7586690 to your computer and use it in GitHub Desktop.
android state codes string array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<string-array name="states"> | |
<item>AL</item> | |
<item>AR</item> | |
<item>AZ</item> | |
<item>CA</item> | |
<item>CO</item> | |
<item>CT</item> | |
<item>DE</item> | |
<item>DC</item> | |
<item>FL</item> | |
<item>GA</item> | |
<item>HI</item> | |
<item>ID</item> | |
<item>IL</item> | |
<item>IN</item> | |
<item>IA</item> | |
<item>KS</item> | |
<item>KY</item> | |
<item>LA</item> | |
<item>ME</item> | |
<item>MD</item> | |
<item>MA</item> | |
<item>MI</item> | |
<item>MN</item> | |
<item>MS</item> | |
<item>MO</item> | |
<item>MT</item> | |
<item>NE</item> | |
<item>NV</item> | |
<item>NH</item> | |
<item>NJ</item> | |
<item>NM</item> | |
<item>NY</item> | |
<item>NC</item> | |
<item>ND</item> | |
<item>OH</item> | |
<item>OK</item> | |
<item>OR</item> | |
<item>PA</item> | |
<item>RI</item> | |
<item>SC</item> | |
<item>SD</item> | |
<item>TN</item> | |
<item>TX</item> | |
<item>UT</item> | |
<item>VT</item> | |
<item>VA</item> | |
<item>WA</item> | |
<item>WV</item> | |
<item>WI</item> | |
<item>WY</item> | |
</string-array> |
Thank you so much lol
Rock!
You're the best 👍
Believe it's missing AK for Alaska though
Thank you so much!
For those who arrived here via Google like I did, keep in mind that these state codes are organized alphabetically according the themselves, not according to the alphabetical order of their full text equivalent.
You cannot us the index of an alphabetically organized list of state names to get the state's code from this list.
Here's one you can split:
<string-array name="us_states">
<item>Alabama,AL</item>
<item>Alaska,AK</item>
<item>American Samoa,AS</item>
<item>Arizona,AZ</item>
<item>Arkansas,AR</item>
<item>California,CA</item>
<item>Colorado,CO</item>
<item>Connecticut,CT</item>
<item>Delaware,DE</item>
<item>District of Columbia,DC</item>
<item>Florida,FL</item>
<item>Georgia,GA</item>
<item>Guam,GU</item>
<item>Hawaii,HI</item>
<item>Idaho,ID</item>
<item>Illinois,IL</item>
<item>Indiana,IN</item>
<item>Iowa,IA</item>
<item>Kansas,KS</item>
<item>Kentucky,KY</item>
<item>Louisiana,LA</item>
<item>Maine,ME</item>
<item>Maryland,MD</item>
<item>Massachusetts,MH</item>
<item>Michigan,MI</item>
<item>Micronesia,FM</item>
<item>Minnesota,MN</item>
<item>Mississippi,MS</item>
<item>Missouri,MO</item>
<item>Montana,MT</item>
<item>Nebraska,NE</item>
<item>Nevada,NV</item>
<item>New Hampshire,NH</item>
<item>New Jersey,NJ</item>
<item>New Mexico,NM</item>
<item>New York,NY</item>
<item>North Carolina,NC</item>
<item>North Dakota,ND</item>
<item>Northern Marianas Islands,MP</item>
<item>Ohio,OH</item>
<item>Oklahoma,OK</item>
<item>Oregon,OR</item>
<item>Palau,PW</item>
<item>Pennsylvania,PA</item>
<item>Puerto Rico,PR</item>
<item>Rhode Island,RI</item>
<item>South Carolina,SC</item>
<item>South Dakota,SD</item>
<item>Tennessee,TN</item>
<item>Texas,TX</item>
<item>Utah,UT</item>
<item>Vermont,VT</item>
<item>Virginia,VA</item>
<item>Virgin Islands,VI</item>
<item>Washington,WA</item>
<item>West Virginia,WV</item>
<item>Wisconsin,WI</item>
<item>Wyoming,WY</item>
</string-array>
Thank you and also @herbig for the more robust solution!
Thank you for sharing If you wan to get states and code list separately you can utilize my class which uses rxjava to separate lists.
import java.util.List;
import io.reactivex.Observable;
import io.reactivex.annotations.NonNull;
import io.reactivex.functions.Function;
/**
* Created by gokhan.alici on 5.10.2017.
*/
public class StateSeparator {
public static final String NULL = null;
private static final int STATE_INDEX = 0;
private static final int STATE_CODE_INDEX = 0;
public static final int STATE_AND_CODE_LENGTH = 2;
public static List<String> getStateList(String[] stateWithCodeList) {
return splitAndTakeList(STATE_INDEX, stateWithCodeList);
}
public static List<String> getStateCodeList(String[] stateWithCodeList) {
return splitAndTakeList(STATE_CODE_INDEX, stateWithCodeList);
}
private static List<String> splitAndTakeList(int selectionIndex, String[] list) {
return Observable.fromArray(list)
.map(new Separator())
.map(new Selector(selectionIndex)).toList().blockingGet();
}
private static class Separator implements Function<String, String[]> {
public static final String[] EMPTY = null;
public static final String SEPARATOR = ",";
@Override
public String[] apply(@NonNull String stateWitCode) throws Exception {
if (StringUtil.isEmpty(stateWitCode)) {
return EMPTY;
}
return stateWitCode.split(SEPARATOR);
}
}
private static class Selector implements Function<String[], String> {
private int selectedIndex;
private Selector(int selectedIndex) {
this.selectedIndex = selectedIndex;
}
@Override
public String apply(@NonNull String[] stateAndCode) throws Exception {
if (CollectionUtil.isEmpty(stateAndCode)) {
return NULL;
}
if (stateAndCode.length != STATE_AND_CODE_LENGTH) {
return NULL;
}
return stateAndCode[selectedIndex];
}
}
}
You rock
Thank you very much.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks!