File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes how to compare two strings having first few letter common Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "how to compare two strings having first few letter common" Watch "how to compare two strings having first few letter common" New topic
Author

how to compare two strings having first few letter common

tej ku
Greenhorn

Joined: Mar 13, 2010
Posts: 19
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

Joined: Aug 16, 2005
Posts: 13875
    
  10

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...


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
tej ku
Greenhorn

Joined: Mar 13, 2010
Posts: 19
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

Joined: Nov 23, 2006
Posts: 9

There is also public boolean startsWith(String prefix)
tej ku
Greenhorn

Joined: Mar 13, 2010
Posts: 19
Thanks for the reply it solved...............
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

@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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to compare two strings having first few letter common
 
Similar Threads
how many objects are eligible for garbage collection?
Quicky String Question
how many objects are eligible for garbage collection?
how to compare two strings having first few charaters common?
compareTo