All possible combinations of an array

前端 未结 7 638
甜味超标
甜味超标 2020-11-30 05:51

I have an string array

{\"ted\", \"williams\", \"golden\", \"voice\", \"radio\"}

and I want all possible combinations of these keywords in

7条回答
  •  野性不改
    2020-11-30 06:34

    package rnd;
    
    import java.util.ArrayList;
    
    public class Rnd {
        public static void main(String args[]) {
            String a[] = {"ted", "williams", "golden", "voice", "radio"};
            ArrayList result =new ArrayList<>();
            for(int i =0 ;i< a.length; i++){
                String s = "";
                for(int j =i ; j < a.length; j++){
                    s += a[j] + " " ;
                    result.add(s);
                }
            }
        }
    }
    

提交回复
热议问题