Home > Blockchain >  How to check if a character is inside a String in Java
How to check if a character is inside a String in Java

Time:04-21

I have a number (example number: L68528050) and want to check if the first position is part of the following String:

s="1234567890ZCFGHJKLMNPRTVWXY"

if its part of it should return true

Thank your for help

CodePudding user response:

Assuming I understand you correctly, you want to check if String s contains "L"?

String numberToCheck = "L68528050".substring(0,1);

String s = "1234567890ZCFGHJKLMNPRTVWXY";

if (s.contains(numberToCheck)) System.out.println("Found it.");

CodePudding user response:

If the given string must be at the beginning:

return s.startsWith(str)

If the given string can be in any position:

return s.contains(str) 
  •  Tags:  
  • java
  • Related