提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
确定指定的单词是否已经添加到数组中。
/* 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++) {