Here you can find the source of firstMatch(List
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. |
public static String firstMatch(List<String> src, String... lookup)
//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; } }