简体   繁体   English

Java将单词的txt列表相互连接

[英]Java Concatenate a txt list of words with one another

I am looking for the most efficient way to combine strings with one another from a list, I have around 2,000 words within a txt file that I read in and store within an arraylist, I then perform transformations on each of the words....I am now looking for a way to loop through the arraylist and perform all possible combinations of words (combining each word with every other word testing if it is correct then try another). 我正在寻找一种最有效的方式来将列表中的字符串相互组合,我在txt文件中存储了大约2,000个单词,并将其存储在arraylist中,然后对每个单词进行转换。我现在正在寻找一种遍历arraylist并执行所有可能的单词组合的方法(将每个单词与其他每个单词组合在一起测试是否正确,然后尝试另一个)。 So each concatenation will be two words, then try another two words....etc until all combinations are completed. 因此,每个串联将是两个单词,然后尝试另外两个单词.... etc,直到完成所有组合。

I would use a nested foreach loop: 我将使用嵌套的foreach循环:

for(String one : list){
    for(String two : list){
        //...
    }
}

and concatenate one and two in both loops. 并在两个循环中连接onetwo

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM