Friday, June 17, 2011

Searching the elements of a String array, starts with SEARCHTEXT (String)


Searching the elements of a String array, starts with SEARCHTEXT (String)

public static ArrayList<String> searchFromStart(String[] inputArray, String searchText) {

            ArrayList<String> outputArray = new ArrayList<String>();

            for (int i = 0; i < inputArray.length; i++) {

                        if (searchText.compareToIgnoreCase(inputArray[i].substring(0,
                                                searchText.length())) == 0) {

                                    outputArray.add(inputArray[i]);

                        }

            }

            return outputArray;
}