Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

3
  • Thanks @Chris Long I found out the problem and rectified it. In the meantime can you please suggest what can I do if I have to compare to strings of different length, in my case s1 and s2, should I create any char array or not? Commented Dec 14, 2014 at 5:28
  • You do not need to create a char array. s1.length is 4.You do not need a char array to count the length of a string. Commented Dec 14, 2014 at 10:50
  • You don't ever need to create the arrays, because you can use the charAt method to access a String's characters, but then I assume that this is some sort of homework assignment, because otherwise you'd be using String.equals() instead of writing your own. If you're just testing for equality / non-equality, your initial comparison of the String's lengths is valid, and you only need to compare the characters of strings that are equal lengths. If you want to do a more complex comparison (deciding which sorts first alphabetically, for example), then you need to specify that. Commented Dec 15, 2014 at 14:57