We need to write a method that generates int[] , each value of which will correspond to the position of the letter of a particular word ( String , we will transfer to this method) relative to the alphabet, i.e. need to get something like this:
SOMEWORDS | 743295618 STAR | 3412 LETTER | 314526 D - The first letter (relative to the alphabet) in the word → _ _ _ _ _ _ _ 1 _E - second → _ _ _ 2 _ _ _ 1 _M - third → _ _ 3 2 _ _ _ 1 _
etc.
If the letters are repeated, the first one that is included in the word is numbered first.
In the code below, I tried to get rid of duplicate characters and sort the string (suggested by enSO), but, having done this, I realized that I don’t understand anything and don’t know what to do next:
TreeSet<Character> keyTreeSet = new TreeSet<Character>(); for (int i = 0; i < keywordArray.length; i++) { keyTreeSet.add(keyword.charAt(i)); } Iterator iterator; iterator = keyTreeSet.iterator(); StringBuilder s = new StringBuilder(); while (iterator.hasNext()) { s.append(iterator.next()); }