Java Utililty Methods List First Item

List of utility methods to do List First Item

Description

The list of methods to do List First Item are organized into topic(s).

Method

ListmergePreserveOrder(List first, List second)
merge Preserve Order
List<String> out = new ArrayList<>();
int i = 0;
int j = 0;
while (i < first.size() || j < second.size()) {
    while (i < first.size() && j < second.size() && first.get(i).equals(second.get(j))) {
        out.add(first.get(i));
        i++;
        j++;
...
booleanmoveItemKindInFirst(final List list)
move Item Kind In First
boolean noItemKind = true;
if (list.contains("dmap.itemkind")) {
    list.remove("dmap.itemkind");
    list.add(0, "dmap.itemkind");
    noItemKind = false;
return noItemKind;
ListnullSafeAppend(List first, List second)
This method joins two lists returning the a single list consisting of the first followed by the second.
return nullSafeAppend(first, second, false);
ListorderByFirstOccurenceInText(String listToOrder[], String textToParse, boolean fuzzy)
This function sorts the Strings in the given list by their first occurence in the given text.
List<String> sortedList = new ArrayList<String>();
HashMap<Integer, String> h = new HashMap<Integer, String>();
if (listToOrder != null && !textToParse.equals("")) {
    for (String s : listToOrder) {
        if (textToParse.indexOf(s) > 0) {
            h.put(textToParse.indexOf(s), s);
    List<Integer> keys = new ArrayList<Integer>(h.keySet());
    Collections.sort(keys);
    for (Integer k : keys) {
        sortedList.add(h.get(k));
if (fuzzy) {
    sortedList.addAll(orderByFuzzyFirstOccurenceInText(listToOrder, textToParse));
return sortedList;
ListorderByFuzzyFirstOccurenceInText(String listToOrder[], String textToParse)
This function sorts the Strings in the given list by their first occurrence in the given text.
List<String> sortedList = new ArrayList<String>();
HashMap<Integer, String> h = new HashMap<Integer, String>();
if (listToOrder != null && !textToParse.equals("")) {
    for (String stringTokens : listToOrder) {
        String[] tokens = stringTokens.split(" ");
        for (String token : tokens) {
            if (textToParse.indexOf(token) > 0 && token.length() > 3) {
                h.put(textToParse.indexOf(token), token);
...
List>permutationsWithFirstElement(List listings)
permutations With First Element
List<T> list = new ArrayList<T>(listings);
list.remove(0);
List<List<T>> perms = permutations(list);
for (List<T> l : perms) {
    l.add(listings.get(0));
list = new ArrayList<T>();
list.add(listings.get(0));
...
Listprepend(String first, List list)
prepend
return merge(Arrays.asList(first), list);
voidputFirstLast(List list)
put First Last
list.add(list.get(0));
list.remove(0);
TremoveFirst(final List list)
Removes the first object from the given List.
if (!isEmpty(list) && 0 < list.size()) {
    return list.remove(0);
return null;
ListremoveFirst(List list)
remove First
if (list != null && list.size() > 0) {
    List<T> newList = new ArrayList<T>();
    for (int i = 1; i < list.size(); i++) {
        T t = list.get(i);
        newList.add(t);
    return newList;
} else {
...