Sorting Strings and extracting common elements of two String arrays in Java

前端 未结 8 1084
南方客
南方客 2020-12-22 12:01

I was asked to write down a Java function sharedStr that by given 2 sorted arrays of Strings, returns the number of Strings that appea

8条回答
  •  自闭症患者
    2020-12-22 12:26

    What does it mean sorted arrays that contains strings? There isn't any special description of the way it has been sorted. what is the basic ordinary sorting of strings?

    It means the elements in the array are ordered in a natural sequence. For strings this is alphebetical order with lowercase words place before upper case.

    How does one compare between two strings any way?

    By invoking the compareTo method. If it returns 0 they strings are equal, if return < 0 the first string is lower than the second, if return > 0 the firs string is higher than the second.

    As for how to count repetitions linearly see this: comparing strings in java

提交回复
热议问题