This example will show how to parse a zip code from a string using java, guava, and apache commons. A zip code is a group of five or nine numbers that are added to a postal address to assist the sorting of mail. ZIP codes are a system of postal codes used by the United States Postal Service (USPS) since 1963.
Straight up Java
This example will separate a string into zip code pieces using core java String.substring.
This snippet will use guava to split a zip code string based on delimiter using google guava. Splitter will break apart a string based on the delimiter '-' and return an Iterable with the zip5 in position zero and zip4 in second element.
Using Guava Splitter again, this snippet will demonstrate how to parse a zip code based on a fixed length.