Question: I want to make a program in Java that could remove duplicated words in a text file. I'm a rookie in programming and I've been googling but I haven't found an understandable guideline to create such a program. I'm not asking for a completed program as an answer (although that is very desirable :p), but I'd really like some suggestions on how to develop this program. Please, anyone? I can manage programming, I just don't know what steps should be taken here.

Answer: 
Just for fun, I wrote a quick solution, which uses the [Guava library](https://code.google.com/p/guava-libraries/) heavily to avoid boilerplate IO code. 

The key is **[LinkedHashMap](http://docs.oracle.com/javase/7/docs/api/java/util/LinkedHashMap.html)**, part of standard Java SDK, which is a Set (i.e. a duplicate-free collection) whose elements are kept in insersertion-order.

This approach is exactly what **[eis commented](https://stackoverflow.com/questions/20451575/how-to-create-a-java-program-that-removes-duplicated-words-from-text-file/20451781#comment30556226_20451575)**, with LinkedHashMap used as the "structure that doesn't allow duplicates".

```
private static void removeDuplicateWords(File file) {
    try {
        String contents = Files.toString(file, Charsets.UTF_8);
        String[] words = contents.split("\\s+"); // or however you define "word"!

        // UsingLinkedHashSet to remove duplicates while retaining order
        LinkedHashSet<String> linkedHashSet = Sets.newLinkedHashSet();
        Collections.addAll(linkedHashSet, words);

        String newContents = Joiner.on(" ").join(linkedHashSet);
        Files.write(newContents, file, Charsets.UTF_8);

    } catch (IOException e) {
        System.out.println(e);
    }
}

```
Use String.split(" ") to get all the words in your text to array (String[]), then append them into a SET so no duplicats will appear. Now go with loop over the array to re-write the text and erase the matching word from the SET. add condition the if a word is in the araay but not in the SET (means that it's duplicate) It will not be re-write

hopes it helps