• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to compare two strings having first few letter common

 
tej ku
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I have
string1 = "caselevelno"
string2 = "caselevelnoversion1"

string2 has more charaters than string1

How to compare and verify that string2 starts with string1 value.?
Regards,
Ravi.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15216
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lookup the API documentation of class java.lang.String and see if there's a method that might do what you're looking for.

Hint: There is such a method and it has a very obvious name...
 
tej ku
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I guess this is the method you are talking about but I need to compare first few charaters of string2 with string1.
contentEquals

public boolean contentEquals(CharSequence cs)
 
John Mercier
Greenhorn
Posts: 26
Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is also public boolean startsWith(String prefix)
 
tej ku
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply it solved...............
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@John: we strive not to provide direct answers (particularly in the SCJP forum???) but rather point people in the right direction: it's better to help people learn how to learn than to just spoonfeed answers.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic