Answers for "java string contains char"

10

contains example in java

String s1 = "My name is GFG"; 
  
// prints true 
System.out.println(s1.contains("GFG")); 
  
// prints false 
System.out.println(s1.contains("geeks"));
Posted by: Guest on May-11-2020
3

java if string contains character

if (string.contains(character)
Posted by: Guest on August-04-2020
1

check if a string contains a character java

string.indexOf('a')
Posted by: Guest on April-23-2021
3

java string contains char

/*
    This method returns true if the given string contains
    the char n. It is necessary due to the
    obsolescence of some compilers, which requires us
    to write our own contains method.
    */
    public static boolean contains_char (String main, char secondary)
    {
        boolean contains_result = false;
        for (int i = 0 ; i < input.length () ; i++)
        {
            if (input.charAt (i) == secondary)
            {
                contains_result = true;
                break;
            }
        }
        return contains_result;
    }

/*
for two chars:
*/
public static boolean contains_dualchar (String main, String secondary)
    {
        boolean contains_result = false;
        for (int i = 0 ; i < input.length () ; i++)
        {
            if (input.charAt (i) == secondary.charAt (0))
            {
                if (input.charAt (i + 1) == secondary.charAt (1))
                {
                    contains_result = true;
                    break;
                }
            }
        }
        return contains_result;
    }
Posted by: Guest on February-23-2020
0

check if a string contains a charater java

javaCopyimport java.util.*;
import java.lang.*;
import java.io.*;

public class Example1 {
    public static void main(String[] args) {
        String str = "Character";
        System.out.println(str.contains("h"));
        System.out.println(str.contains("Char"));
        System.out.println(str.contains("ac"));
        System.out.println(str.contains("v"));
        System.out.println(str.contains("vl")); 
    }
}
Posted by: Guest on August-08-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language