Java List Search search(String[] searchList, String s)

Here you can find the source of search(String[] searchList, String s)

Description

search

License

Open Source License

Parameter

Parameter Description
searchList list for seaching
s search string

Return

true if search string exists in list, false otherwise

Declaration

public static boolean search(String[] searchList, String s) 

Method Source Code

//package com.java2s;
/* Copyright (C) 2009 SRI International
  *// w w w  .j a  v  a2  s . co m
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
  * as published by the Free Software Foundation; either version 2
  * of the License, or (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  */

import java.util.*;

public class Main {
    /**
     *
     * @param searchList list for seaching
     * @param s search string
     * @return true if search string exists in list, false otherwise
     */
    public static boolean search(String[] searchList, String s) {
        if (null == s || null == searchList) {
            return false;
        }
        for (int i = 0; i < searchList.length; i++) {
            if (0 == searchList[i].compareTo(s)) {
                return true;
            }
        }
        return false;
    }

    /**
     *
     * @param searchList Vector for seaching
     * @param s search string
     * @return true if search string exists in list, false otherwise
     */
    public static boolean search(Vector searchList, String s) {
        if (null == s || null == searchList) {
            return false;
        }
        for (int i = 0; i < searchList.size(); i++) {
            if (true == ((String) searchList.get(i)).equals(s)) {
                return true;
            }
        }
        return false;
    }
}

Related

  1. search(List> collection, T element)
  2. searchReplace(String key, String value, List lines)