+ 2

JAVA

How to compare String prefix and suffix if an argument is passed to the string ???

14th Apr 2017, 8:51 AM
PAVAN REDDY
PAVAN REDDY - avatar
5 Respostas
+ 23
You can use startsWith() and endsWith() methods. String str = "Java is fun"; if(str.startsWith("Java")){ // true } if(str.endsWith("fun"){ // true } Also look for how to use matches() method in Google. You can compare any substring using this.
14th Apr 2017, 9:32 AM
Shamima Yasmin
Shamima Yasmin - avatar
+ 5
An example please.
14th Apr 2017, 9:20 AM
Meharban Singh
Meharban Singh - avatar
+ 1
Hi meharban my query is if the string has the same prefix and suffix of 3characters then we have to remove suffix in that string. For example : If string is JAVAJAV it should print JAVA. another example : if string is LEARNLEA IT should print LEA.
14th Apr 2017, 9:47 AM
PAVAN REDDY
PAVAN REDDY - avatar
+ 1
If String is LEARNLEA Then it should print LEARN. Hope u understood now...
14th Apr 2017, 9:48 AM
PAVAN REDDY
PAVAN REDDY - avatar
+ 1
Yes i got it on by own without google.. i thought till now I'm zero at programming after solving this I'm having confidence by programming skills has improved to 1%
14th Apr 2017, 11:35 AM
PAVAN REDDY
PAVAN REDDY - avatar