Yes. Exactly the same as for HashMap except that it's already sorted.
Have a look at the methods for TreeMap in the API documentation. You will find all kinds of methods for getting the keys, the values, iterators for looping through them etc. You can use those methods to access your data any way you want so you can send it to a file any way you want.
We all start by learning arrays, but in real life its much more common to use Lists and Maps etc because these are more powerful and easier to work with. You'll learn all about them sooner or later...

so i should delete this hashmap codes and change it to tree map?

Yes. Everywhere you have "HashMap" replace that with "TreeMap".

hi james,

i did browse through but no api explained how to output it to text file?any suggestions?

its toString() method gives you a beautiful text version (its what you get when you print the TreeMap). Now you have a String its easy to write that to a file.

haha..yeah how foolish i am. Thanks james.

hi,

is hashmap allowing duplicate values? Thanks.

The codes still showing duplicated values.

hi,

its said that A Map cannot contain duplicate keys; each key can map to at most one value. but in my case it still allow duplicate values to be added in.

Any suggestions?thanks.

2nd. parts from my last post, I can see that

A Map does not allow duplicate keys. If you want multiple values for one key you have to wrap them in (eg) a List - which is exactly what we have done here. Ie: each key (bigram ) is unique and points to a single value that is an ArrayList containing all the words with that bigram in them.
Where exactly are your duplicates? I think your current code given a word like "winning" with a bigram on "in" would add "winning" twice to the ArrayList - but that's a piece of logic you can fix for yourself.

hi

how do i sort the hashmap values?thanks. using the treemap only?or should i iterate every single string again?thanks

I said this more than once. Re-read my previous posts.

hi,

i am implement prevent duplicates for the hashmap by using

//remove duplicates of words
            Set set = new HashSet();
            ArrayList newList = new ArrayList();
            for (Iterator iter = allwords.iterator(); iter.hasNext();) {
                Object element = iter.next();
                if (set.add(element)) {
                    newList.add(element);
                }
            }

            allwords.clear();
            allwords.addAll(newList);

some of the words never get duplicated when added into the hashmap but some words are duplicated and still being added in. any suggestion what is wrong? i lower case everything all the words.

Where exactly are words being duplicated? Can you provide an example?

hi,

does hash set take words : hello and HeLlo as two different words?it seems to be case..how should i remove the duplicate with such funny pattern HeLLo in hashset?thanks.

Yes, they are different Strings with different hash values. If the capitalisation doesn't matter you should convert them all to upper (or lower) case right at the start.

its seems very weird..because in one bigram for example "el" the welcome come out once only but in bigram "we" the welcome come out twice

so

el = welcome
we = welcome, welcome

any suggestions as what might be wrong in the reading of the words?

Hang on, this is going wrong, and it's my fault.
It's essential that you develop your own skills in analysing problems, researching, reading the API, and trying& debugging solutions. What's happening here is that you are asking me before exhausting those processes, and I'm encouraging that by answering too quickly.
For you own benefit I'm going to limit this to one question/answer per morning or afternoon (excluding follow-ups for clarification only). Sorry if that sounds harsh or unkind, but it's time for you to fly on your own wings.
J

commented: Your patience is admirable. +2

alright james.

no problem. :) but can i ask one more question regarding the hashmap and its iteration?seem its very long to remove the duplicates. so is there any better algorithm out there that i can use?thanks..:)

I think that you didn't read some posts in this thread and linked tutorials, just for you, with intends stop this thread

links as I posted contains full example FindDups.java plus words saved in File

one more question regarding the hashmap

So this is this morning's quota answer:
re-read previous posts. I told you repeatedly what to do with your HashMaps, and asked repeatedly for clarification as to where the duplicates were happening (which you never answered properly). There's really nothing I can add regarding your duplicates at this point.
Either use your IDE's step execution / variables tracing, or add lots and lots of print statements to your code so you can see for yourself what's happening.

hi james,

Thanks for the feedback. Anyway this is sound stupid but lets say i have

public TextFileIndexer(String INDEX_COLLECTION) throws IOException {
        writer = new IndexWriter(INDEX_COLLECTION, new StandardAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
    }

public static void searchIndex(String words) throws IOException, ParseException{

        System.out.println("Searching for '" + words + "'"  );
        Directory directory = FSDirectory.getDirectory(how to get variable INDEX_COLLECTION);

how do i get the variable INDEX_COLLECTION from TextFileIndexer and put it into searchIndex class?

Hello again.
I don't know what this is about - where does this code come from?
TextFileIndexer and searchIndex are not classes, they are methods. They will be defined inside a (or two) classes, but that info is not in your post.
INDEX_COLLECTION is not a variable, it's a parameter that has to be passed into the TextFileIndexer method. You can't "get it". You have to look for where that method is being called and see what value is being passed in.
Sorry, but without a lot more info on what this is all about I don't know what other help I can give.

ps: This seems like a completely different problem from the ArrayList / TreeMap thing we were discussing before. Maybe you should mark this thread as "solved" and start a new one for this new problem.

commented: such patience. kudos. :D +2
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.