我有一個循環搜索字典,提取我已經過濾的單詞,然後將它放入一個arrayList。然後我想優化我的搜索並從這個arrayList中提取單詞,並將它放在另一個單詞中。有沒有一種方法來生成一個arrayList?通常我想要做的事情我可能不知道我可能需要多少個arrayLists。如何自動生成數組列表?
我有一個手機鍵盤,每個編號分配3-4個字母。例如編號1(a,b,c)。我試圖編寫一個方法,例如當我輸入1234時,我希望它能夠通過程序可以訪問的單詞庫的幫助來預測我正在嘗試編寫的單詞。所以,當我按1時,我從庫中提取所有以a,b或c開頭的獨特單詞。然後我考慮已經被按下的數字2(d,e,f),並從前面的列表中提取以a,b,c開始的所有單詞,但是具有作爲第二個字符d,e或f的所有單詞。我正在做的是試圖產生新的數組列表來放置新的過濾詞。我只是不知道如何自動創建數組列表的生成。
我的示例代碼:
//cycles through each possible alaphabetical characters represented by the numbers that constitute "signature"
for (int countSignature = 0; countSignature < signature.length();countSignature++){
if (signature.codePointAt(countSignature) == 50) {// Representing 2
for (int j = 0; j < set1.size(); j++){ //iterating through the array for each word that starts with a,b, or c.
if (arraySet1[j].codePointAt(countSignature) == 97
|| arraySet1[j].codePointAt(countSignature) == 98
|| arraySet1[j].codePointAt(countSignature) == 99) {
arrayListSet2.add(arraySet1[j]);
//need to generate new arrayList for the next round of filtering.
f(j++)
}
}
}else if(signature.codePointAt(countSignature) == 51){ // Representing 3
for (int j = 0; j < set1.size(); j++) {
if (arraySet1[j].codePointAt(countSignature) == 100
|| arraySet1[j].codePointAt(countSignature) == 101
|| arraySet1[j].codePointAt(countSignature) == 102) {
arrayListSet2.add(arraySet1[j]);
}
}
}else if(signature.codePointAt(countSignature) == 52){ // Representing 4
for (int j = 0; j < set1.size(); j++) {
if (arraySet1[j].codePointAt(countSignature) == 103
|| arraySet1[j].codePointAt(countSignature) == 104
|| arraySet1[j].codePointAt(countSignature) == 105) {
arrayListSet2.add(arraySet1[j]);
}
}
}else if(signature.codePointAt(countSignature) == 53){ // Representing 5
for (int j = 0; j < set1.size(); j++) {
if (arraySet1[j].codePointAt(countSignature) == 106
|| arraySet1[j].codePointAt(countSignature) == 107
|| arraySet1[j].codePointAt(countSignature) == 108) {
arrayListSet2.add(arraySet1[j]);
}
}
}else if(signature.codePointAt(countSignature) == 54){ // Representing 6
for (int j = 0; j < set1.size(); j++) {
if (arraySet1[j].codePointAt(countSignature) == 109
|| arraySet1[j].codePointAt(countSignature) == 110
|| arraySet1[j].codePointAt(countSignature) == 111) {
arrayListSet2.add(arraySet1[j]);
}
}
}else if(signature.codePointAt(countSignature) == 55){ // Representing 7
for (int j = 0; j < set1.size(); j++) {
if (arraySet1[j].codePointAt(countSignature) == 112
|| arraySet1[j].codePointAt(countSignature) == 113
|| arraySet1[j].codePointAt(countSignature) == 114
|| arraySet1[j].codePointAt(countSignature) == 115){
arrayListSet2.add(arraySet1[j]);
}
}
}else if(signature.codePointAt(countSignature) == 56){ // Representing 8
for (int j = 0; j < set1.size(); j++) {
if (arraySet1[j].codePointAt(countSignature) == 116
|| arraySet1[j].codePointAt(countSignature) == 117
|| arraySet1[j].codePointAt(countSignature) == 118) {
arrayListSet2.add(arraySet1[j]);
}
}
}else if(signature.codePointAt(countSignature) == 57){ // Representing 9
for (int j = 0; j < set1.size(); j++) {
if (arraySet1[j].codePointAt(countSignature) == 119
|| arraySet1[j].codePointAt(countSignature) == 120
|| arraySet1[j].codePointAt(countSignature) == 121
|| arraySet1[j].codePointAt(countSignature) == 122) {
arrayListSet2.add(arraySet1[j]);
}
}
}else{
System.out.println("");
}
}
你可能想重新考慮你的邏輯.. – Maroun
邏輯不清楚。你需要更多的這個。 – Ajit
http://stackoverflow.com/questions/1480663/how-can-i-slice-an-arraylist-out-of-an-arraylist-in-java – Rossiar