Opening text document and put it in alphabetical order


So, I can’t provide a code example in Java as I’m not familiar with it whatsoever, but this is C# and they’re fairly similar languages if I’m not mistaken. I can’t say it’s the most efficient way, but it will work.

Based on your description, I’m assuming you’ve reached the point where you have a list of words. In my example, my list doesn’t have any entries but let’s just pretend it does.

List<string> words = new List<string>();

for (int i = 0; i < words.Count; i++)
    string currentWord = words[i];

    for (int j = i + 1; j < words.Count; j++)
        if (currentWord == words[j])
            // You have a duplicate word

You can’t compare Strings with the == operator in java, instead use the .equals(String) method. Another option is to use compareTo(String) method.

compareTo will return a number less than 0 if the element comes before what it is being compared to, greater than 0 if element goes after what it’s being compared to and returns 0 if they are equal.

Something like this: (Obviously don’t call peek with an empty OrderedList like I did haha)

if( !String.isNullOrEmpty(currentString) && currentString.equals(new OrderedList<String>().peek()) )
  return "";

What the **** are any of you saying?

Honestly, you could watch like three introductory videos about Java or C# and (assuming they go over basic stuff like loops and variables and equalities and stuff) you could understand it very easily. This (no offense to OP) is pretty basic compared to what kind of problems you can encounter as a computer scientist.