is a HashMap the right choice here?
in
Programming Questions
•
1 years ago
(small part of the code)
I need to know if i added a word or not, so the hashMap is now like:
HashMap<String, String>
And when i put something in the hashmap the key and value are the same, like:
exceptWords.put("theSame", theSame");
I could use a arrayList aswel and check for contains(String ...)
it's not that i need the best thing for speed atm, i'm just wondering for the purpose of learning what coding wise is the best.
[code]
// dump words except -worker, was, while, when, after- and the neighbors of those on pos = 1
ArrayList<Word> dumpWords = ta.getWords();
String[] except = {"worker", "was", "while", "when", "after" };
HashMap<String, String> exceptWords = new HashMap<String, String>();
// get the neighbors of the except words on pos = 1
for(int i = 0; i < except.length; i++) {
Word w = ta.getWord(except[i]);
ArrayList<NearWord> nearWords = w.getNearWords(1);
for(NearWord nw : nearWords) {
exceptWords.put(nw.word, nw.word);
}
}
}[/code]
I need to know if i added a word or not, so the hashMap is now like:
HashMap<String, String>
And when i put something in the hashmap the key and value are the same, like:
exceptWords.put("theSame", theSame");
I could use a arrayList aswel and check for contains(String ...)
it's not that i need the best thing for speed atm, i'm just wondering for the purpose of learning what coding wise is the best.
[code]
// dump words except -worker, was, while, when, after- and the neighbors of those on pos = 1
ArrayList<Word> dumpWords = ta.getWords();
String[] except = {"worker", "was", "while", "when", "after" };
HashMap<String, String> exceptWords = new HashMap<String, String>();
// get the neighbors of the except words on pos = 1
for(int i = 0; i < except.length; i++) {
Word w = ta.getWord(except[i]);
ArrayList<NearWord> nearWords = w.getNearWords(1);
for(NearWord nw : nearWords) {
exceptWords.put(nw.word, nw.word);
}
}
}[/code]
1