-
/*Java Search String using indexOf ExampleThis example shows how we can search a word within a String object usingindexOf method.*/
public class SearchStringExample
{
public static void main(String[] args)
{//declare a String objectString strOrig = “Hello world Hello World”;
/*To search a particular word in a given string use indexOf method.indexOf method. It returns a position index of a word within the stringif found. Otherwise it returns -1.*/
int intIndex = strOrig.indexOf(“Hello”);
if(intIndex == – 1){System.out.println(“Hello not found”);}else{System.out.println(“Found Hello at index “ + intIndex);}
/*we can also search a word after particular position usingindexOf(String word, int position) method.*/
int positionIndex = strOrig.indexOf(“Hello”,11);System.out.println(“Index of Hello after 11 is “ + positionIndex);
/*Use lastIndexOf method to search a last occurrence of a word within string.*/int lastIndex = strOrig.lastIndexOf(“Hello”);System.out.println(“Last occurrence of Hello is at index “ + lastIndex);
}}
/*Output of the program would be :Found Hello at index 0Index of Hello after 11 is 12Last occurrence of Hello is at index 12*/
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