0
Could any of you guy tell me how to get a list of random orders of the given string in java?
10 Respuestas
+ 2
Your question is unclear.
Can you give an example of the input and expected output?
+ 2
I think I got it and I really appreciate each of your answers
thanks you all
+ 1
For example,if your input is "ABC",I want to get a list of possible orders like "CBA","ACB","CAB",etc.....
+ 1
Killiam Chances it's permutation
https://code.sololearn.com/cMwSt8bMGAeH/?ref=app
+ 1
Okay
0
Killiam Chances Do you mean to randomly arrange elements of a list?
0
Yes, one way to get a list of random orders of a given string in Java is to convert the string to a list of characters, shuffle the list using the `Collections.shuffle()` method, and then convert the list back to a string. Here is an example:
```
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class StringRandomizer {
public static void main(String[] args) {
String inputString = "example";
List<Character> charList = new ArrayList<>();
for (char c : inputString.toCharArray()) {
charList.add(c);
}
Collections.shuffle(charList);
StringBuilder sb = new StringBuilder();
for (char c : charList) {
sb.append(c);
}
String outputString = sb.toString();
System.out.println(outputString);
}
}
```
In this example, we first convert the input string to a list of characters, shuffle the list using `Collections.shuffle()`, and then convert the shuffl
0
You can used random function?