About 346,000 results
Open links in new tab
  1. Searching For Characters and Substring in a String in Java

    Dec 2, 2024 · In this article, we will explore essential methods like indexOf (), contains (), and startsWith () to search characters and substrings within strings in Java. 1. Using indexOf(char c) The indexOf() searchesfor the first occurrence of a character from the beginning of the string and returns its index. If the character is not found, it returns -1.

  2. java - How to search a string in another string? - Stack Overflow

    Feb 14, 2012 · How would I search for a string in another string? This is an example of what I'm talking about: If the string "word" is in the string "text", the method "findInString (String, String)" returns true else it returns false. Use the String.indexOf(String str) method. From the JavaDoc:

  3. String Searching Methods in Java

    Java provides several methods to search within strings, each suited for different needs. The contains() method checks for the presence of a substring, while indexOf() and lastIndexOf() methods find the position of a substring or character.

  4. String (Java Platform SE 8 ) - Oracle Help Center

    The class String includes methods for examining individual characters of the sequence, for comparing strings, for searching strings, for extracting substrings, and for creating a copy of a string with all characters translated to uppercase or to lowercase.

  5. java - Search for a word in a String - Stack Overflow

    May 1, 2014 · If you are looking up one string inside another you should be using indexOf or contains method. Example: See if "foo" is present in a string. But if you are looking for a pattern use the match method. Example: See if "foo" is present at the beginning/end of the string. Or see if it's present as a whole word.

  6. string - Substring search in Java - Stack Overflow

    For an exact String comparison, you can simply do: boolean match = stringA.equals(stringB); If you want to check that a string contains a substring, you can do: boolean contains = string.contains(substring); For more String methods, see the javadocs

  7. Java String Search Examples - Online Tutorials Library

    Explore various examples of string search methods in Java. Learn how to efficiently find substrings, indexes, and patterns with practical code snippets.

  8. Searching Characters in a String in Java - Online Tutorials Library

    Learn how to search for characters in a string using Java. Explore methods like indexOf, lastIndexOf, and more with practical examples.

  9. Java String search

    The String class has two methods to search a string for a specified character or substring: indexOf() Searches for the first occurrence of a character or substring.

  10. Navigating the String Universe: Search and Replace in Java

    The lesson covers fundamental Java String methods that enable searching and replacing specific characters and substrings within strings. Students learn how to use 'indexOf' and 'lastIndexOf' to find character positions, 'contains' to check for the existence of substrings, and 'replace' and 'replaceAll' to modify string content.