Java examples for java.lang:String Compare
Compares two strings provided and returns an expected integer value based on the comparison
//package com.java2s; public class Main { public static void main(String[] argv) { String str1 = "java2s.com"; String str2 = "java2s.com"; System.out.println(compareStrings(str1, str2)); }//from w w w .j a v a2 s . c om /** * Compares two strings provided and returns an expected integer value based on the comparison * @param str1 * @param str2 * @return int */ public static int compareStrings(String str1, String str2) { if (str1 == null) return -1; if (str2 == null) return -1; if (str1.length() != str2.length()) return -1; return str1.compareTo(str2); } }