Here you can find the source of getYear(String strDate)
public static String getYear(String strDate)
//package com.java2s; /**//from w w w. j a v a 2s . co m * * Methods Descrip:Converts a line of text into an array of lower case words * using a BreakIterator.wordInstance(). * <p> * * This method is under the Jive Open Source Software License and was * written by Mark Imbriaco. * * @param text * a String of text to convert into an array of words * @return text broken up into an array of words. * */ public class Main { public static String getYear(String strDate) { String year = ""; if (strDate != null && !strDate.equals("")) { strDate = strDate.trim(); year = getElement(strDate.split("-"), 0); } return year; } private static String getElement(String[] strs, int number) { String elemenet = ""; if (strs != null) { int length = strs.length; if (number > length) { elemenet = strs[length]; } else { elemenet = strs[number]; } } return elemenet; } }