0

I got this set of string such as "12 13 2 1 444"

I want to generate all of different permutation of this set of integers.

I mean

"12 13 2 1 444"
"13 12 2 1 444"
"12 13 1 2 444"
"1 12 13 2 444"
.....

Could any one help me with Java?

ergosys
  • 47,835
  • 5
  • 49
  • 70
Josh Morrison
  • 7,488
  • 25
  • 67
  • 86

2 Answers2

2

There are many ways to do this. I think that the best way is to break this down into two steps:

  1. Break the string down into its component parts.
  2. Generate all permutations of those parts.

You can split the string into individual values by using the String.split method:

String[] allParts = inputString.split(' ');

Once you have this, you can generate all permutations with one of many permutation generation functions. Leon's link will probably help out here.

templatetypedef
  • 362,284
  • 104
  • 897
  • 1,065
1

you need to do it recursively. Check http://programminggeeks.com/recursive-permutation-in-java/ as a guide

Leon
  • 1,141
  • 13
  • 25