-
/*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
-
from gtts import gTTS import os def create_audiobook(text_file, output_file): with open(text_file, 'r', encoding='utf-8...
-
This textbook grew out of notes for the ECE143 Programming for Data Analysis class that the author has been teaching at University of Cali...
-
Data Science Crash Course for Beginners with Python... Uncover the energy of records in 30 days with Python Data Science 2024! Are you sea...
-
This practical guide provides a collection of techniques and best practices that are generally overlooked in most data engineering and dat...
-
Through a recent series of breakthroughs, deep learning has boosted the entire field of machine learning. Now, even programmers who know c...
-
from imdb import IMDb ia = IMDb() movie_name = input("Enter the movie name: ") movies = ia.search_movie(movie_name) if movies: ...
-
What you'll learn Play the role of a Data Scientist / Data Analyst working on a real project. Demonstrate your Skills in Python - the ...
-
What you'll learn Create basic visualizations such as line graphs, bar graphs, and pie charts using Excel spreadsheets. Explain the im...
-
import plotly.express as px country = input("Enter the country name: ") data = { 'Country': [country], 'Valu...
-
There are 4 modules in this course Python is now becoming the number 1 programming language for data science. Due to python’s simplicity a...
Categories
AI
(31)
Android
(24)
AngularJS
(1)
Assembly Language
(2)
aws
(17)
Azure
(7)
BI
(10)
book
(4)
Books
(146)
C
(77)
C#
(12)
C++
(82)
Course
(67)
Coursera
(197)
Cybersecurity
(24)
data management
(11)
Data Science
(106)
Data Strucures
(8)
Deep Learning
(13)
Django
(14)
Downloads
(3)
edx
(2)
Engineering
(14)
Excel
(13)
Factorial
(1)
Finance
(6)
flask
(3)
flutter
(1)
FPL
(17)
Google
(20)
Hadoop
(3)
HTML&CSS
(47)
IBM
(25)
IoT
(1)
IS
(25)
Java
(93)
Leet Code
(4)
Machine Learning
(46)
Meta
(18)
MICHIGAN
(5)
microsoft
(4)
Pandas
(3)
PHP
(20)
Projects
(29)
Python
(878)
Python Coding Challenge
(281)
Questions
(2)
R
(70)
React
(6)
Scripting
(1)
security
(3)
Selenium Webdriver
(2)
Software
(17)
SQL
(42)
UX Research
(1)
web application
(8)
0 Comments:
Post a Comment