Skip to content

Commit 58f2dcf

Browse files
committed
Add blogpost and fix some issue
1 parent 5f17733 commit 58f2dcf

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

_posts/java-string/2019-11-30-compare-two-strings-lexicographically-in-java.md

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,12 @@ Compairing character sequence of thirdString (Butter) to the character sequence
102102
Compairing character sequence of fourthString (Cheese) to the character sequence of firstString (Paneer) returns: -13
103103
```
104104
Explanation:
105-
1. In first case, compareTo() method returns zero since firstString and secondString are same.
106-
2. In second case, compareTo() method returns 14 since secondString follows thirdString by 14 characters. The pictorial explanation for this case is given below.
107-
105+
1. In first case,`compareTo()` method returns zero since firstString and secondString are same.
106+
2. In second case, `compareTo()` method returns 14 since secondString follows thirdString by 14 characters. The pictorial explanation for this case is given below.
108107
![An explanation for the second case of the java program for `compareTo()` method](/assets/images/2019-11-30/comapreto-method-secondstring-compareto-thirdstring.png)
109108

110-
3. In third case, compareTo() method returns -1 since thirdString precedes fourthString by 1 character.
111-
4. In last case, compareTo() method returns -13 since fourthString precedes firstString by 13 characters. The pictorial explanation for this case is given below.
109+
3. In third case, `compareTo()` method returns -1 since thirdString precedes fourthString by 1 character.
110+
4. In last case, `compareTo()` method returns -13 since fourthString precedes firstString by 13 characters. The pictorial explanation for this case is given below.
112111

113112
![An explanation for the fourth case of the java program for `compareTo()` method](/assets/images/2019-11-30/comapreto-method-fourthString-compareto-firstString.png)
114113

@@ -123,8 +122,8 @@ First, we will see the logic, how can we build the logic for our user-defined me
123122
2. Apply while loop for condition `k`<`lim` where k is integer variable initiated with 0.
124123

125124
3. Apply if condition to check if the character at an index k of both the strings is not similar; if the condition returns the difference between these two characters.
126-
127-
We will cast the difference as integer value so that the difference between the Unicode value of character will be return.
125+
126+
We will cast the difference as integer value so that the difference between the Unicode value of character will be return.
128127

129128
4. If the if condition is false, the while loop will continue for the rest of the iterations until condition is true i.e `k`<`lim`.
130129

@@ -201,12 +200,12 @@ Compairing firstString (Paneer) to the fifthString (PaneerButter) returns: -6
201200
```
202201
## Conclusion
203202
We have seen how to compare two strings lexicographically in Java. As per the articles, there are two ways to do the same
204-
1. Using the Java compareTo() method
203+
1. Using the Java `compareTo()` method
205204
2. By creating a user-defined method
206205

207-
In a first way, I am using the compareTo() method of the Java and in the second way I have created the user-defined method compareToString().
206+
In a first way, I am using the `compareTo()` method of the Java and in the second way I have created the user-defined method `compareToString()`.
208207

209-
Most noteworthy, In compareTo() method of the Java, the comparison is based on the Unicode value of each character in the strings.
208+
Most noteworthy, In `compareTo()` method of the Java, the comparison is based on the Unicode value of each character in the strings.
210209

211210
If you found this article worth, please [Give me a cup of Coffee ☕](https://www.paypal.me/GauravKukade)
212211

0 commit comments

Comments
 (0)