提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
检查数组中是否包含项
/* 来自 *时 代 Java 公 众 号 - nowjava.com*/ //package com.nowjava; public class Main { public static void main(String[] argv) throws Exception { int content = 2; int[] nums = new int[] { 34, 35, 36, 37, 37, 37, 67, 68, 69 }; System.out.println(contains(content, nums)); } public static boolean contains(int content, int[] nums) { boolean yes = false; for (int i : nums) { if (content == i) /* from N o w J a v a . c o m - 时 代 Java*/ yes = true; } return yes; } public static boolean contains(String content, String[] nums) { boolean yes = false; for (String i : nums) { if (content.equals(i)) yes = true; } return yes; } public static boolean contains(char content,