1package com.mkyong.core;
2
3import java.util.Arrays;
4import java.util.List;
5
6public class StringArrayExample1 {
7
8 public static void main(String[] args) {
9
10 String[] alphabet = new String[]{"A", "B", "C"};
11
12 // Convert String Array to List
13 List<String> list = Arrays.asList(alphabet);
14
15 if(list.contains("A")){
16 System.out.println("Hello A");
17 }
18
19 }
20
21}
22Copy
1import java.util.Scanner;
2public class Search_Element
3{
4 public static void main(String[] args)
5 {
6 int n, x, flag = 0, i = 0;
7 Scanner s = new Scanner(System.in);
8 System.out.print("Enter no. of elements you want in array:");
9 n = s.nextInt();
10 int a[] = new int[n];
11 System.out.println("Enter all the elements:");
12 for(i = 0; i < n; i++)
13 {
14 a[i] = s.nextInt();
15 }
16 System.out.print("Enter the element you want to find:");
17 x = s.nextInt();
18 for(i = 0; i < n; i++)
19 {
20 if(a[i] == x)
21 {
22 flag = 1;
23 break;
24 }
25 else
26 {
27 flag = 0;
28 }
29 }
30 if(flag == 1)
31 {
32 System.out.println("Element found at position:"+(i + 1));
33 }
34 else
35 {
36 System.out.println("Element not found");
37 }
38 }
39}
1 // Convert to stream and test it
2 boolean result = Arrays.stream(alphabet).anyMatch("A"::equals);
3 if (result) {
4 System.out.println("Hello A");
5 }
6Copy