I have following Java code,
int a[] = new int[] {20, 30} ;
List lis = Arrays.asList(a) ;
System.out.print(lis.contains(20));
However, output is false. Can anybody help me, why this is not giving True ?
What you get is not a list of integers but a list of integer arrays, i.e. List<int[]>. You can't create collections (like List) of primitive types.
In your case, the lis.contains(20) will create an Integer object with the value 20 and compare that to the int array, which clearly isn't equal.
Try changing the type of the array to Integer and it should work:
Integer a[] = new Integer[] {20, 30} ;
List lis = Arrays.asList(a) ;
System.out.print(lis.contains(20));
List yourself), but if you use Guava, you can use Ints.asList(int[]) on an int[] directly.