Java的:检查是否一个字符串是在一本字典 [英] Java: Check if a string is in a dictionary
问题描述
我有一个语言的字典(即英语,意大利语,等...),基本上是一个字每行一个文件。
I have a language dictionary (i.e. english,italian,etc...), that essentially is a file with one word on every line.
现在我想用给定的字符串输入检查,如果该字符串存在到该词典的方法创建一个类。
Now i want to create a class with a method that given a string in input check if that string exists into that dictionary.
我的想法是,该方法返回一个布尔值。在伪code:
My idea is that the method return a boolean value. In pseudocode:
boolean checkWord(String s){
if(StringIsInDictionary) return true;
return false
}
应该是什么来实现该功能的最佳方式?
What should be the best way to implement that feature?
考虑到该文件将包含〜65000字。
Consider that the file will contain ~65000 words.
推荐答案
阅读字典成<一个href="http://docs.oracle.com/javase/7/docs/api/java/util/Set.html"><$c$c>Set<String>$c$c> (例如,<一href="http://docs.oracle.com/javase/7/docs/api/java/util/HashSet.html"><$c$c>HashSet<String>$c$c>),然后用<一个href="http://docs.oracle.com/javase/7/docs/api/java/util/Set.html#contains%28java.lang.Object%29"><$c$c>set.contains(word)$c$c>.
这篇关于Java的:检查是否一个字符串是在一本字典的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!