Java List First Item firstMatch(List src, String... lookup)

Here you can find the source of firstMatch(List src, String... lookup)

Description

first Match

License

Apache License

Parameter

Parameter Description
src The list on which we iterate to match against the lookup.
lookup The list being matched against an entry for the source.<br> </br> The first match breaks the loop and is sufficient.

Return

: - the first match between a value in src against the lookup. - null if the lookup is null - null if there's no match

Declaration

public static String firstMatch(List<String> src, String... lookup) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.Arrays;

import java.util.List;

public class Main {
    /**/*from   www  . java 2 s.  c  o m*/
     * @param src    The list on which we iterate to match against the lookup.
     * @param lookup The list being matched against an entry for the source.<br>
     * </br> The first match breaks the loop and is sufficient.
     * @return :
     * - the first match between a value in src against the lookup.
     * - null if the lookup is null
     * - null if there's no match
     */
    public static String firstMatch(List<String> src, String... lookup) {
        if (lookup == null) {
            return null;
        }

        Arrays.sort(lookup);
        for (String s : src) {
            int matchedIndex = Arrays.binarySearch(lookup, s);
            if (matchedIndex >= 0) {
                return lookup[matchedIndex];
            }
        }
        return null;
    }
}

Related

  1. firstBoolean(List list)
  2. firstColumnRemovable(List data)
  3. firstElement(List list)
  4. firstItem(Iterable list)
  5. firstItem(List items)
  6. firstObjectFromList(List list)
  7. firstOrDefault(List items)
  8. firstStartsWith(List lines, String startsWith)
  9. firstUnique(List list)