boolean (String item) { final String newItem = item.trim(); if (newItem.isEmpty()) { return false; } final int length = myFullList.size(); int index = -1; for (int i = 0; i < length; i++) { if (StringUtil.equalsIgnoreCase(myFullList.get(i), newItem)) { index = i; break; } } if (index == 0) { // item is already at the top of the list return false; } if (index > 0) { // move item to top of the list myFullList.remove(index); } else if (myFullList.size() >= myHistorySize && myFullList.size() > 0) { // trim list myFullList.remove(myFullList.size() - 1); } insertElementAt(newItem, 0); return true; }