【发布时间】:2016-04-20 02:34:53
【问题描述】:
我正在创建一个程序,该程序将使用 200,000 多个单词的读入文件向用户输入的文本消息提供建议(如拼写检查)。
我需要创建一个读取单词数组的方法(已根据消息的长度排序到位置 0-n),然后将位置 n 处的每个字符替换为左侧的相应字符或键盘上的右侧并将它们存储到 ArrayList 中。然后,这将被传递给一个方法,该方法将读取 ArrayList,将其与读入的字典交叉引用,并返回一个 ArrayList,其中的组合实际上是单词。
EX:你好(位置 0)那里(位置 1) 替代词:Hello、Jello、Gello、Hrllo、Hwllo 等
我一直在努力寻找一种方法来将位置 n 处的字符替换为键盘左侧或右侧的字符。有什么建议吗?
这是目前为止的代码:
public ArrayList <String> alternateWords (String [] w)
{
//declarations
int p = 0; //position of characters inside array
ArrayList<String> potentialWords = new ArrayList<String>(); //ArrayList to hold all potential words
//Traverse array and replace letters in each word, then store in ArrayList
for (int i = 0; i < w.length; i++) //loop for each word in a text message
{
for (int j = 0; j < w[p].length(); i++) //loop for each character in a text message
{
//REPLACE HAPPENS HERE
p++; //increment position of character check
//Store in arrayList
} //End inner For
} //End outer For
} //End alternateWords
【问题讨论】:
标签: java arrays string arraylist replace