Java:获取未反转字符串数组的所有对组合的算法

Java:获取未反转字符串数组的所有对组合的算法,java,Java,我有一个字符串数组: List<String> st=new ArrayList<String>(); st.add("Massachusetts institute"); st.add("of"); st.add("Technology"); 当然也包括长度更大的字符串,例如: List<String> st=new ArrayList<String>(); st.add("Massachusetts institute"); st.add

我有一个字符串数组:

List<String> st=new ArrayList<String>();
st.add("Massachusetts institute"); 
st.add("of");
st.add("Technology");
当然也包括长度更大的字符串,例如:

List<String> st=new ArrayList<String>();
st.add("Massachusetts institute"); 
st.add("of");
st.add("Technology");
st.add("MIT");

在没有空白格式的情况下,我做了以下工作:

// Your code
List<String> st=new ArrayList<String>();
st.add("Massachusetts institute "); 
st.add("of ");
st.add("Technology ");
st.add("MIT");
/* Added a few more to st for my own tests - see IDEONE link below */
//-------------------------------------------------------------------

/* Additional code */
Set<String> combs = new HashSet<String>(); // Set of matches default 16 spaces
/* The code should work even if the size goes above 16 - tried it in IDEONE */

int p = st.size(); // Get the endpoint

for(int i =0; i<p; i++){
     for(int j=i+1; j<p; j++) {
         combs.add(st.get(i) + st.get(j));
    }
}
Iterator g = combs.iterator();

while(g.hasNext()) {
    System.out.println(g.next());
}
}
/************************************************/
//您的代码
List st=新的ArrayList();
st.add(“麻省理工学院”);
st.add.(“of”);
st.add(“技术”);
圣加达(“MIT”);
/*为我自己的测试在st中添加了更多内容-请参阅下面的IDEONE链接*/
//-------------------------------------------------------------------
/*附加代码*/
Set combs=new HashSet();//匹配集默认为16个空格
/*该代码应该工作,即使大小超过16-尝试在IDEONE*/
int p=标准尺寸();//获取端点

对于(int i=0;i尝试使用CombinaticsLib生成特定大小的组合。应该可以做到这一点。
-Massachusetts institute
-of
-Technology
-MIT
-Massachusetts institute, of
-Massachusetts institute, Technology
-Massachusetts institute, MIT
-of, Technology
-of, MIT
-Technology, MIT
-Massachusetts institute, of, Technology
-Massachusetts institute, of, MIT
-Massachusetts institute, Technology, MIT
-Massachusetts institute, of, Technology, MIT
// Your code
List<String> st=new ArrayList<String>();
st.add("Massachusetts institute "); 
st.add("of ");
st.add("Technology ");
st.add("MIT");
/* Added a few more to st for my own tests - see IDEONE link below */
//-------------------------------------------------------------------

/* Additional code */
Set<String> combs = new HashSet<String>(); // Set of matches default 16 spaces
/* The code should work even if the size goes above 16 - tried it in IDEONE */

int p = st.size(); // Get the endpoint

for(int i =0; i<p; i++){
     for(int j=i+1; j<p; j++) {
         combs.add(st.get(i) + st.get(j));
    }
}
Iterator g = combs.iterator();

while(g.hasNext()) {
    System.out.println(g.next());
}
}
/************************************************/