集册 Java实例教程 确定指定的词是否已添加到数组中。

确定指定的词是否已添加到数组中。

欢马劈雪     最近更新时间:2020-01-02 10:19:05

441
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
确定指定的单词是否已经添加到数组中。
/* from 
N o w  J a v a  . c o m*/


//package com.nowjava;


public class Main {

    public static void main(String[] argv) throws Exception {

        String word = "nowjava.com";

        String[] array = new String[] { "1", "abc", "level", null,

                "nowjava.com", "asdf 123" };

        System.out.println(wordAlreadyAdded(word, array));

    }


    /**

     * Determines whether a specified word has already been added to the array.

     * 

     * @param word

     *            -- the word to search for in the array

     * @param array

     *            -- the array to be searched

     * @return whether the word has already been added to the array

     */

    private static boolean wordAlreadyAdded(String word, String[] array) {

        for (int i = 0; i < array.length; i++) {

            
展开阅读全文