-
/*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
-
Deep learning is at the heart of modern Artificial Intelligence — powering technologies like chatbots, recommendation systems, image recog...
-
Explanation: ๐น Step 1: Create List x = [1,2,3] A list x is created ๐ Values inside list: 1, 2, 3 ๐น Step 2: Understand sum() Function su...
-
What you'll learn Understand why version control is a fundamental tool for coding and collaboration Install and run Git on your local ...
-
Introduction Deep learning is one of the most powerful branches of AI, enabling systems to learn complex patterns from data by mimicking ...
-
Explanation: ๐น 1. Creating the List x = [[1]*2]*2 ๐ Break it step by step: [1]*2 → creates [1, 1] [[1]*2]*2 → creates two references to ...
-
When people think about data science, they often focus on tools like Python, machine learning models, or deep learning frameworks. But beh...
-
๐ Day 27/150 – Print Even Numbers up to N in Python Printing even numbers up to N is a great way to understand loops, conditions, and n...
-
Explanation: ๐น 1. Function Definition def func(): This line defines a function named func. It does not take any arguments. Because it use...
-
Explanation: ๐ง 1. Operator Precedence (Priority Rules) In Python, logical operators follow this order: and → evaluated first or → evaluat...
-
Code Expanation: ๐น Step 1: Create List x = [0, 1, 2] A list x is created ๐ Elements: 0, 1, 2 ๐น Step 2: Understand all() Function all(x)...
Categories
100 Python Programs for Beginner
(119)
AI
(254)
Android
(25)
AngularJS
(1)
Api
(7)
Assembly Language
(2)
aws
(29)
Azure
(10)
BI
(10)
Books
(262)
Bootcamp
(11)
C
(78)
C#
(12)
C++
(83)
Course
(87)
Coursera
(300)
Cybersecurity
(30)
data
(5)
Data Analysis
(32)
Data Analytics
(22)
data management
(15)
Data Science
(353)
Data Strucures
(17)
Deep Learning
(158)
Django
(16)
Downloads
(3)
edx
(21)
Engineering
(15)
Euron
(30)
Events
(7)
Excel
(19)
Finance
(10)
flask
(4)
flutter
(1)
FPL
(17)
Generative AI
(72)
Git
(10)
Google
(51)
Hadoop
(3)
HTML Quiz
(1)
HTML&CSS
(48)
IBM
(42)
IoT
(3)
IS
(25)
Java
(99)
Leet Code
(4)
Machine Learning
(292)
Meta
(24)
MICHIGAN
(5)
microsoft
(11)
Nvidia
(8)
Pandas
(14)
PHP
(20)
Projects
(32)
pytho
(1)
Python
(1328)
Python Coding Challenge
(1132)
Python Mistakes
(51)
Python Quiz
(490)
Python Tips
(5)
Questions
(3)
R
(72)
React
(7)
Scripting
(3)
security
(4)
Selenium Webdriver
(4)
Software
(19)
SQL
(49)
Udemy
(18)
UX Research
(1)
web application
(11)
Web development
(8)
web scraping
(3)

0 Comments:
Post a Comment