java - Checking if an array of string is sorted lexicographically case insensitive -


i'm writing method gets input array of strings , integer n. method check if strings until length n in lexicographical order. code returns false every input , cant figure out why!

public static boolean isstringarraysorted(string[] strs, int n) {     boolean answer=true;       (string word : strs) {         for(int i=1; i<strs.length; i++) {             string check1 =word.substring(0,n);              string check2= strs[i].substring(0,n);             if ( check1.comparetoignorecase(check2) > 0 )                 return false;          }     }      return answer;  } 

because iterating in inner loop entire array while should word onwards.

for (int j=1; j<strs.length; j++){     for(int i=j+1; i<strs.length; i++){         string word = strs[j];         string check1 =word.substring(0,n);          string check2= strs[i].substring(0,n);         if (check1.comparetoignorecase(check2)>0)             return false;       } } 

Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -