You can use string.indexOf('a').
If the char a is present in string :
Answer from mP. on Stack Overflowit returns the the index of the first occurrence of the character in the character sequence represented by this object, or -1 if the character does not occur.
You can use string.indexOf('a').
If the char a is present in string :
it returns the the index of the first occurrence of the character in the character sequence represented by this object, or -1 if the character does not occur.
String.contains()which checks if the string contains a specified sequence of char valuesString.indexOf()which returns the index within the string of the first occurence of the specified character or substring (there are 4 variations of this method)
JAVA - String contains char letter. Possible to check? - Stack Overflow
file - How to see if a string contains a specific char in Java? - Stack Overflow
Java why i cant check if string contains char?
How to check for invalid characters in a string?
Hello, i have a array that contains string example: String[]test={“hello”, “bob”} i want to check in a loop if test[x].contains(c); where c is char c = word.chartAt(y); its says that contains in string cannot be applied to char. But why i can do if(test[x].contains(“char”); but not replace char by c since its also a char .. thanks
The problem is that string length is compared to character value:
str.length() == chr
What you should use if the indexOf String method
public boolean contains(String str, char chr) {
return str.indexOf(chr) != -1;
}
You are testing if the length of the String is equal to some char. This will perhaps work if your String is of length zero and your character == 0 or perhaps if your String is of length one and you compare it to the character with the numeric value of 1. In other words: Almost never.
You never return false. So all your string contain all your characters.
String has an indexOf( character ) method. use that. See documentation.
char is not CharSequence
Your call to String::contains takes a CharSequence such as String while you are passing a char. Two different types.
Use the double-quote mark rather than single-quote mark around < to get a String object rather than a char primitive: "<" versus '<'.
boolean containsLessThan = input.contains( "<" ) ;
If your goal is simply deletion of such characters, use String::replace.
String result = input.replace( "<" , "" ).replace( ">" , "") ;
FYI, the char type is obsolete, unable to represent even half of the characters defined in Unicode.
Here is a chart I created showing the various text-related classes bundled with Java. String is one of several classes that implement the CharSequence interface. The char type is not included here because it is (a) a primitive rather than a class, and (b) obsolete.

By the way, recommended reading: The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)
You can use info.indexOf('<')
it returns the the index of the first occurrence of the character in the character sequence represented by this object, or -1 if the character does not occur.
So this would be your code: if(info.indexOf('<') > -1)
Strong Recommendation: Please first search enough and/or read the right documentation for each part of the code that you're working with or each time get stuck. Asking question would be the last choice when you absolutely devistated. Here is exactly what you asked for example:
https://stackoverflow.com/questions/506105/how-can-i-check-if-a-single-character-appears-in-a-string#:~:text=You%20can%20use%20string.,the%20character%20does%20not%20occur.