Search code examples
javaarrayssortingcategorization

String array Categorizing


I have a string array where I want to check each element in the array with 8 other array elements to see if any of those element in the first array element categorize under any of them.

Simply I want to categorize a string array. So in order to do that I have to check with 8 other arrays (Because I have 8 categories) I want to know an efficient way to do this without looping one by one


Solution

  • You can sort the array and then use Arrays.binarySearch() method instead of looping one by one. It is more efficient way to search a particular element.