List of utility methods to do Collection Last
Object | getLast(Collection c) Returns the last element in a collection (by exhausting its iterator in case it is not a list). if (c instanceof List) return getLast((List) c); Object result = null; Iterator it = c.iterator(); do { result = it.next(); } while (it.hasNext()); return result; ... |
T | getLastElement(Collection Method which will return the "last" element in the given collection or a null value if not found. T elem = defaultValue; if (collection != null && !collection.isEmpty()) { if (List.class.isAssignableFrom(collection.getClass())) { elem = ((List<T>) collection).get(collection.size() - 1); } else { for (T item : collection) { elem = item; return elem; |
T | getLastElement(final Collection get Last Element if (isEmpty(collection)) { return null; if (collection instanceof List) { List<T> list = (List<T>) collection; return list.get(list.size() - 1); } else { T last = null; ... |
T | getLastOfCollection(Collection get Last Of Collection T t = (T) collection.toArray()[collection.size() - 1];
return t;
|
T | getLastOrNull(Collection get Last Or Null if (collection.isEmpty()) { return null; } else if (collection instanceof List) { List<T> list = (List<T>) collection; return list.get(list.size() - 1); } else { Iterator<T> iterator = collection.iterator(); T last = null; ... |
String | implodeCollection(Collection> items, String prefix, String suffix, String delimiter, String lastItemSuffix) Glue together all items into one String. if (items == null) throw new NullPointerException("items argument may not be null"); if (prefix == null) prefix = ""; if (suffix == null) suffix = ""; if (delimiter == null) delimiter = ""; ... |
int | lastIndexOfObjectIdentity(Collection Returns the index position of the last occurring object within the Collection . int retval = -1; if (collection != null) { Iterator<E> iterator = collection.iterator(); if (iterator != null) { int indexPosition = 0; boolean lastElementWasIdenticalElement = false; while ((retval < 0 || lastElementWasIdenticalElement) && iterator.hasNext()) { lastElementWasIdenticalElement = false; ... |