I have the string below that i got from opening a file containing a list of US of states an their capitals
String text = "US_states"; //text file with US States and capitols
byte[] buffer = null;
InputStream is;
try {
is = getAssets().open(text);
int size = is.available(); //size of the file in bytes
buffer = new byte[size]; //declare the size of the byte array with size of the file
is.read(buffer); //read file
is.close(); //close file
} catch (IOException e) {
e.printStackTrace();
}
String str_data = new String(buffer); // Store text file data in the string variable
}
Now I'd like to parse this string and insert it into a map objet Map m = new HashMap(); but I am not sure how to parse/split the various elements...
State Capital ---------------- --------------- Alabama Montgomery Alaska Juneau Arizona Phoenix Arkansas Little Rock California Sacramento Colorado Denver Connecticut Hartford Delaware Dover Florida Tallahassee Georgia Atlanta Hawaii Honolulu Idaho Boise Illinois Springfield Indiana Indianapolis Iowa Des Moines Kansas Topeka Kentucky Frankfort Louisiana Baton Rouge Maine Augusta Maryland Annapolis Massachusetts Boston Michigan Lansing Minnesota Saint Paul Mississippi Jackson Missouri Jefferson City Montana Helena Nebraska Lincoln Nevada Carson City New Hampshire Concord New Jersey Trenton New Mexico Santa Fe New York Albany North Carolina Raleigh North Dakota Bismarck Ohio Columbus Oklahoma Oklahoma City Oregon Salem Pennsylvania Harrisburg Rhode Island Providence South Carolina Columbia South Dakota Pierre Tennessee Nashville Texas Austin Utah Salt Lake City Vermont Montpelier Virginia Richmond Washington Olympia West Virginia Charleston Wisconsin Madison Wyoming Cheyenne