提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
是数组中包含的项
// 来 自 NowJava.com - 时 代 Java //package com.nowjava; public class Main { public static void main(String[] argv) throws Exception { String object = "nowjava.com"; String[] array = new String[] { "1", "abc", "level", null, "nowjava.com", "asdf 123" }; System.out.println(isOnList(object, array)); } public static boolean isOnList(String object, String[] array) { try { for (int i = 0; i < array.length; i++) { if (object.equals(array[i])) { return true; } } } catch (Exception e) {