0

I am writing a code to insert a new word in the dictionary file(given). I was adding the new word in the ArrayList and then sorting the array to keep a sorted dictionary by collection.sort(ArrayList<E> e) but it is not full-filling my requirement as my dictionary is A a aa aab . . . but when I sort it all caps are listed above then all small letter words like A Aaina Aab . . . a aa aab

Can you help me in inserting words without changing the order?

Narmeen25
  • 35
  • 1
  • 4
  • You want to sort a list of String in a case insensitive way. See this question and its answers: http://stackoverflow.com/questions/7469643/how-to-sort-alphabetically-while-ignoring-case-sensitive – Cyrille Ka Oct 30 '13 at 15:51

3 Answers3

1

You can do like this

Collections.sort(list,String.CASE_INSENSITIVE_ORDER);
Prabhakaran Ramaswamy
  • 25,706
  • 10
  • 57
  • 64
0

You might be better off storing the entries in a TreeSet:

TreeSet<String> entries = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER).

This will likely be more efficient than repeated adding to a list then sorting. (I took it as implied that you are appending to the list and then sorting for each entry added; this will likely get slow for a large dictionary. Not an issue though, if you are sorting the list after you have added all the entries.)

To get the entries back out in order iterate the set - entries.iterator().

This has the added (possible) advantage to ignoring duplicates.

Paul
  • 3,009
  • 16
  • 33
0

first ,, try to make all the dictionary case insensitive ,,, then after that add the given word ,, then use collection.sort ,,,, in that sorted array list you have your required index of where it should really be in actual dictionary ,, ,, then put it in that point of case sensitive array ,,,, i have also got the same assignment at my uni ,,, it was one heck of a mess completing it :) regards