Java examples for Collection Framework:Array Contain
Check if an Item is contained in an array
//package com.java2s; 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)); }//ww w . j av a2 s . c o m public static boolean contains(int content, int[] nums) { boolean yes = false; for (int i : nums) { if (content == i) 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, char[] nums) { boolean yes = false; for (char i : nums) { if (content == i) yes = true; } return yes; } }