Java parsing string
I'm looking to parse the following string in java <some lines here> Key1:thingIWantToKnow Key2:otherThing Key3:bla Key4:bla Key5:bla <(possibly) more lines here> All lines end with a newline (\n) character. I'm looking to store the value pair once I find the key's I'm care about. If a Map is what you want: Map<String, String> keyValueMap = new HashMap<String,String>(); String[] lines = input.split("\n"); if (lines == null) { //Compensate for strange JDK semantics lines = new String[] { input }; } for (String line : lines) { if (!line.contains(":")) { //Skip lines that don't contain key-value