-
/*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
-
In today's data-driven world, creating charts is no longer enough. Organizations need professionals who can transform raw numbers into...
-
In today's data-driven world, uncertainty is everywhere. Whether predicting stock market trends, analyzing medical trials, building ma...
-
Deep Learning has revolutionized Artificial Intelligence by enabling machines to recognize images, understand language, generate content, ...
-
Machine Learning has become one of the most transformative technologies of the 21st century, powering everything from recommendation syste...
-
Fundamentals of Data Visualization: A Primer on Making Informative and Compelling Figures (Free PDF)In the era of big data, the ability to communicate information visually has become just as important as collecting or analyzing data. Ever...
-
Introduction In the world of data science and analytics, having strong tools and a solid workflow can be far more important than revisitin...
-
Modern Artificial Intelligence and Machine Learning are built upon a deep mathematical foundation. While many practitioners learn to use f...
-
Introduction to Machine Learning – A Complete Guide to Statistical Learning, Optimization, Kernel Methods, Neural Networks, Generative Mod...
-
Modern data science is built on uncertainty. Whether predicting customer behavior, diagnosing diseases, forecasting financial markets, or ...
-
Introduction Programming becomes meaningful when you build something — not just read about syntax, but write programs that do things. This...
Categories
100 Python Programs for Beginner
(119)
AI
(328)
Android
(25)
AngularJS
(1)
Api
(7)
Assembly Language
(2)
aws
(31)
Azure
(12)
BI
(10)
Books
(318)
Bootcamp
(14)
C
(78)
C#
(12)
C++
(83)
cloud
(1)
Course
(87)
Coursera
(302)
Cybersecurity
(34)
data
(10)
Data Analysis
(43)
Data Analytics
(31)
data management
(16)
Data Science
(413)
Data Strucures
(18)
Deep Learning
(211)
Django
(16)
Downloads
(3)
edx
(21)
Engineering
(15)
Euron
(30)
Events
(7)
Excel
(24)
Finance
(13)
flask
(4)
flutter
(1)
FPL
(17)
Generative AI
(77)
Git
(12)
Google
(54)
Hadoop
(3)
HTML Quiz
(1)
HTML&CSS
(48)
IBM
(43)
IoT
(3)
IS
(25)
Java
(99)
Leet Code
(4)
Machine Learning
(371)
Meta
(24)
MICHIGAN
(5)
microsoft
(13)
Nvidia
(8)
Pandas
(15)
PHP
(20)
Projects
(34)
Python
(1353)
Python Coding Challenge
(1208)
Python Mathematics
(8)
Python Mistakes
(51)
Python Quiz
(588)
Python Tips
(97)
Questions
(3)
R
(72)
React
(7)
Scripting
(3)
security
(4)
Selenium Webdriver
(4)
Software
(21)
SQL
(54)
Udemy
(18)
UX Research
(1)
web application
(11)
Web development
(9)
web scraping
(3)

0 Comments:
Post a Comment