tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 Tools and Libs > Google Guava > Primitives > Integer Contains

Integer Contains 

Google Guava is a java library with lot of utilities and reusable components. This requires the library guava-10.0.jar to be in classpath. The following example shows using Ints.contains() API. It returns TRUE if the given integer array contains specified integer.

File Name  :  
com/bethecoder/tutorials/guava/primitive_tests/IntContainsTest.java 
Author  :  Sudhakar KV
Email  :  [email protected]
   
package com.bethecoder.tutorials.guava.primitive_tests;

import com.google.common.primitives.Ints;

public class IntContainsTest {

  /**
   @param args
   */
  public static void main(String[] args) {
    int [] values = 126854379};

    int val2Find = 6;
    System.out.println("Array contains '" 
        val2Find + "' : " + Ints.contains(values, val2Find));
    
    val2Find = 0;
    System.out.println("Array contains '" 
        val2Find + "' : " + Ints.contains(values, val2Find));
    
    val2Find = 9;
    System.out.println("Array contains '" 
        val2Find + "' : " + Ints.contains(values, val2Find));
  }
}
   

It gives the following output,
Array contains '6' : true
Array contains '0' : false
Array contains '9' : true



 
  


  
bl  br