Skip to content

Instantly share code, notes, and snippets.

@peat-psuwit
Created March 12, 2017 13:36
Show Gist options
  • Save peat-psuwit/429095070d899d443a4cf8a2535d1f61 to your computer and use it in GitHub Desktop.
Save peat-psuwit/429095070d899d443a4cf8a2535d1f61 to your computer and use it in GitHub Desktop.
Parse the string that starts with "A9" (include next 2 letters) and "B1" (include 2 last letters). F2-2016.
import java.util.*;
public class ParseString {
public static ArrayList<String> parse(String input) {
ArrayList<String> result = new ArrayList<>();
String[] splitInput = input.split(",");
for (int i = 0; i < splitInput.length; i++) {
String s = splitInput[i].trim();
if (s.startsWith("A9"))
result.add(s.substring(2, 4));
else if (s.startsWith("B1"))
result.add(s.substring(s.length() - 2));
}
return result;
}
public static void main(String[] args) {
for (int i = 0; i < args.length; i++) {
System.out.println(parse(args[i]));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment