Java ArrayList Search searchString(String name, ArrayList input)

Here you can find the source of searchString(String name, ArrayList input)

Description

This method searchs for a String withing an ArrayList containing strings.

License

Open Source License

Parameter

Parameter Description
name a parameter
input a parameter

Declaration

public static String searchString(String name, ArrayList input) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.ArrayList;

public class Main {
    /**//  w w w  .ja v a  2  s.c  o  m
     * This method searchs for a String withing an ArrayList containing strings.
     * 
     * @param name
     * @param input
     * @return
     */
    public static String searchString(String name, ArrayList input) {

        boolean found = false;
        int i = 0;

        while ((found == false) && (i < input.size())) {
            if (((String) input.get(i)).equals(name)) {
                found = true;
            } else {
                i++;
            }
        }
        if (found) {
            return ((String) input.get(i));
        } else {
            return (null);
        }
    }
}

Related

  1. search(ArrayList src, ArrayList pattern, int start)
  2. search(String token, ArrayList iniTokens)
  3. searchInElement(String name, Map> elementMap)