-
/*Java String Array Contains ExampleThis Java String Array Contains example shows how to find a String inString array in Java.*/
import java.util.Arrays;
public class StringArrayContainsExample {
public static void main(String args[]){
//String arrayString[] strMonths = new String[]{“January”, “February”, “March”, “April”, “May”};
//Strings to findString strFind1 = “March”;String strFind2 = “December”;
/** There are several ways we can check whether a String array* contains a particular string.** First of them is iterating the array elements and check as given below.*/boolean contains = false;
//iterate the String arrayfor(int i=0; i < strMonths.length; i++){
//check if string array contains the stringif(strMonths[i].equals(strFind1)){
//string foundcontains = true;break;
}}
if(contains){System.out.println(“String array contains String “ + strFind1);}else{System.out.println(“String array does not contain String “ + strFind1);}
/** Second way to check whether String array contains a string is to use* Arrays class as given below.*/
contains = Arrays.asList(strMonths).contains(strFind1);System.out.println(“Does String array contain “ + strFind1 + “? “ + contains);
contains = Arrays.asList(strMonths).contains(strFind2);System.out.println(“Does String array contain “ + strFind2 + “? “ + contains);
}}
/*Output of above given Java String Array Contains example would beString array contains String MarchDoes String array contain March? trueDoes String array contain December? false*/
Friday, 13 April 2018
Popular Posts
-
Advantages of Object Oriented Programming Object oriented programming has several advantage to the programmer and user. Through inheri...
-
Build interactive, data-driven websites with the potent combination of open-source technologies and web standards, even if you have only ...
-
What is Python? → Python is an interpreted High level programming Language for General purpose programming. Python is created by Gui...
-
Activity_main.xml File <? xml version= "1.0" encoding= "utf-8" ?> < LinearLayout xmlns: android = &qu...
-
Java :- It is a fast, secure and reliable general purpose computer programming language. Python :- A Readable, efficient and powerfu...
-
Python is a high-level programming language that is widely used in various kinds of programming activities. Python is known for its objec...
-
Business Analytics Definition "Study of business data using statistical technique and programming for creating decision suppo...
-
Variables in R A variables are nothing but reserved memory locations to store values. This means that when you create a variab...
-
Procedure Oriented Programming Language:- High level language such as COBOL , FORTRAN AND C is commonly known as procedure oriented progr...
-
➤Each family of processes has its own set of instructions, the set of instructions are called machine instructions ➤A processor underst...

Categories
Android
(22)
AngularJS
(1)
Assembly Language
(2)
Books
(10)
C
(75)
C#
(6)
C++
(81)
Course
(1)
Data Strucures
(4)
Downloads
(1)
Engineering
(13)
flutter
(1)
FPL
(17)
Hadoop
(1)
HTML&CSS
(38)
IS
(25)
Java
(87)
Leet Code
(4)
PHP
(20)
Projects
(1)
Python
(218)
R
(69)
Selenium Webdriver
(2)
Software
(14)
SQL
(27)

ReplyDeletenice article for beginners.thank you.
javacodegeeks
welookups java