This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • 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
Pie
Posts: 15435
41
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