class StringCompareExample {
public static void main
( String args
[ ] ) { verboseCompare( s1, s2) ;
verboseCompare( s2, s1) ;
verboseCompare( s1, s1) ;
}
System .
out .
println ( "Comparing \" " + s1
+ "\" to \" " + s2
+ "\" ..." ) ;
int comparisonResult = s1.compareTo ( s2) ;
System .
out .
println ( "The result of the comparison was " + comparisonResult
) ;
System .
out .
print ( "This means that \" " + s1
+ "\" " ) ; if ( comparisonResult < 0 ) {
System .
out .
println ( "lexicographically precedes \" " + s2
+ "\" ." ) ; } else if ( comparisonResult > 0 ) {
System .
out .
println ( "lexicographically follows \" " + s2
+ "\" ." ) ; } else {
System .
out .
println ( "equals \" " + s2
+ "\" ." ) ; }
}
}
Y2xhc3MgU3RyaW5nQ29tcGFyZUV4YW1wbGUgewogICAgcHVibGljIHN0YXRpYyB2b2lkIG1haW4oU3RyaW5nIGFyZ3NbXSl7CiAgICAgICAgU3RyaW5nIHMxID0gIlByb2plY3QiOyBTdHJpbmcgczIgPSAiU3VuamVjdCI7CiAgICAgICAgdmVyYm9zZUNvbXBhcmUoczEsIHMyKTsKICAgICAgICB2ZXJib3NlQ29tcGFyZShzMiwgczEpOwogICAgICAgIHZlcmJvc2VDb21wYXJlKHMxLCBzMSk7CiAgICB9CgogICAgcHVibGljIHN0YXRpYyB2b2lkIHZlcmJvc2VDb21wYXJlKFN0cmluZyBzMSwgU3RyaW5nIHMyKXsKICAgICAgICBTeXN0ZW0ub3V0LnByaW50bG4oIkNvbXBhcmluZyBcIiIgKyBzMSArICJcIiB0byBcIiIgKyBzMiArICJcIi4uLiIpOwoKICAgICAgICBpbnQgY29tcGFyaXNvblJlc3VsdCA9IHMxLmNvbXBhcmVUbyhzMik7CiAgICAgICAgU3lzdGVtLm91dC5wcmludGxuKCJUaGUgcmVzdWx0IG9mIHRoZSBjb21wYXJpc29uIHdhcyAiICsgY29tcGFyaXNvblJlc3VsdCk7CgogICAgICAgIFN5c3RlbS5vdXQucHJpbnQoIlRoaXMgbWVhbnMgdGhhdCBcIiIgKyBzMSArICJcIiAiKTsKICAgICAgICBpZihjb21wYXJpc29uUmVzdWx0IDwgMCl7CiAgICAgICAgICAgIFN5c3RlbS5vdXQucHJpbnRsbigibGV4aWNvZ3JhcGhpY2FsbHkgcHJlY2VkZXMgXCIiICsgczIgKyAiXCIuIik7CiAgICAgICAgfWVsc2UgaWYoY29tcGFyaXNvblJlc3VsdCA+IDApewogICAgICAgICAgICBTeXN0ZW0ub3V0LnByaW50bG4oImxleGljb2dyYXBoaWNhbGx5IGZvbGxvd3MgXCIiICsgczIgKyAiXCIuIik7CiAgICAgICAgfWVsc2V7CiAgICAgICAgICAgIFN5c3RlbS5vdXQucHJpbnRsbigiZXF1YWxzIFwiIiArIHMyICsgIlwiLiIpOwogICAgICAgIH0KICAgICAgICBTeXN0ZW0ub3V0LnByaW50bG4oKTsKICAgIH0KfQ==