java string contains char
Java
/*
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;
}
String s1 = "My name is GFG";
// prints true
System.out.println(s1.contains("GFG"));
// prints false
System.out.println(s1.contains("geeks"));
Also in Java:
- Title
- java string to byte array utf8
- Category
- Java
- Title
- java map foreach
- Category
- Java
- Title
- java 8 loop in map
- Category
- Java
- Title
- java last element in array
- Category
- Java
- Title
- parallel sorting in java 8
- Category
- Java
- Title
- how to add a keylistener to a jframe
- Category
- Java
- Title
- java hello world
- Category
- Java
- Title
- convert two bytes to int java
- Category
- Java
- Title
- how to compare strings java
- Category
- Java
- Title
- try block in java
- Category
- Java
- Title
- java round up
- Category
- Java
- Title
- java method overriding
- Category
- Java
- Title
- in javascipt how to stop further page processing
- Category
- Java
- Title
- java jaxb unmarshall xml to map
- Category
- Java
- Title
- how to multiply a number by itself using for loop in java
- Category
- Java
- Title
- java program to get all cat indices in elasticsearch javadoc
- Category
- Java
- Title
- how to add java_home in mac
- Category
- Java
- Title
- room insert and return id
- Category
- Java
- Title
- print a string java
- Category
- Java
- Title
- converting char array to string
- Category
- Java
- Title
- http client java
- Category
- Java
- Title
- generate random number java
- Category
- Java
- Title
- ndroid.support.v4.content.FileProvider
- Category
- Java
- Title
- how to change the color of a menubar in java
- Category
- Java
- Title
- how to get the dimensions of a 2d array in java
- Category
- Java
- Title
- kotlin jsonobject get nested
- Category
- Java
- Title
- java stream find specific element
- Category
- Java
- Title
- logging in java
- Category
- Java
- Title
- find first non repeating character in a string
- Category
- Java
- Title
- java random number generator in range
- Category
- Java
- Title
- java processbuilder example
- Category
- Java
- Title
- replaceall in java
- Category
- Java
- Title
- split every character in string into array java
- Category
- Java
- Title
- java script to detect and launch all browsers
- Category
- Java
- Title
- java polymorphism
- Category
- Java
- Title
- java script num toSting syntax eror
- Category
- Java
- Title
- arrays.fill java
- Category
- Java
- Title
- bracket balancing program in java
- Category
- Java
- Title
- java string split underscore
- Category
- Java
- Title
- android notification addaction example
- Category
- Java
- Title
- iterate map in java 8 using stream
- Category
- Java
- Title
- indexof java
- Category
- Java
- Title
- boolean checkbox swing
- Category
- Java
- Title
- java script how to not allow soace
- Category
- Java
- Title
- how to check the end of a string java
- Category
- Java
- Title
- java convert char to int
- Category
- Java
- Title
- android get distance between two locations kotlin
- Category
- Java
- Title
- java set value of arraylist
- Category
- Java
- Title
- how to convert string to double in android studio
- Category
- Java
- Title
- how to create an array of arraylist in java
- Category
- Java
- Title
- java foreach
- Category
- Java
- Title
- enum with numbers java
- Category
- Java
- Title
- iterate over map keys java
- Category
- Java
- Title
- java script print date in YYYY-MM-DD HH:MM:SS format
- Category
- Java
- Title
- rewrite file java
- Category
- Java
- Title
- java loop through map
- Category
- Java
- Title
- socket programming in java
- Category
- Java
- Title
- list in java
- Category
- Java
- Title
- java catch multiple exceptions
- Category
- Java
- Title
- how to add jar in maven java application in netbeans
- Category
- Java
- Title
- editer un label java
- Category
- Java
- Title
- D/NetworkSecurityConfig: No Network Security Config specified, using platform default
- Category
- Java
- Title
- java 8 findany on null list
- Category
- Java
- Title
- function in java
- Category
- Java
- Title
- and roid shape setCornerRadii
- Category
- Java
- Title
- how to print to the console in java
- Category
- Java
- Title
- validate isbn number java
- Category
- Java
- Title
- java comments
- Category
- Java
- Title
- java method
- Category
- Java
- Title
- java how to get current date
- Category
- Java
- Title
- make a commet in java
- Category
- Java
- Title
- localdate to string java
- Category
- Java
- Title
- java methods
- Category
- Java
- Title
- how to create a subclass in java
- Category
- Java
- Title
- public static void main(string args)
- Category
- Java
- Title
- java 8 collect multiple lists into single list
- Category
- Java
- Title
- java timestamp
- Category
- Java
- Title
- java valeur absolue
- Category
- Java
- Title
- Spring Security JWT Authentication + PostgreSQL – RestAPIs SpringBoot + Spring MVC + Spring JPA
- Category
- Java
- Title
- java initialize float to zero
- Category
- Java
- Title
- java create map
- Category
- Java
- Title
- dataframe to dict without index
- Category
- Java
- Title
- spannable string in android java for color
- Category
- Java
- Title
- java packages example
- Category
- Java
- Title
- how to read in a file in java
- Category
- Java
- Title
- how to iterate hashmap in java
- Category
- Java
- Title
- Spigot API inventory close
- Category
- Java
- Title
- how to create a 2d arraylist java
- Category
- Java
- Title
- select photo from camera android
- Category
- Java
- Title
- basic java coding
- Category
- Java
- Title
- how get started with LWJGL 3
- Category
- Java
- Title
- iterate through hashmap java
- Category
- Java
- Title
- java Convert a string IPv4 IP address to the equivalent long numeric value.
- Category
- Java
- Title
- objectoutputstream exemple
- Category
- Java
- Title
- java print treemap
- Category
- Java
- Title
- entre clavier java
- Category
- Java
- Title
- java permutation
- Category
- Java
- Title
- working with buttons in applet java
- Category
- Java
- Title
- double round java integer
- Category
- Java
- Title
- download spring
- Category
- Java