Below is a Java program to print all permutations of a given string:
```java
import java.util.HashSet;
import java.util.Set;
public class StringPermutations {
public static void main(String[] args) {
String input = "abc"; // Change this string to find permutations of a different string
System.out.println("Permutations of " + input + ":");
Set<String> permutations = generatePermutations(input);
for (String permutation : permutations) {
System.out.println(permutation);
}
}
public static Set<String> generatePermutations(String input) {
Set<String> permutations = new HashSet<>();
if (input == null || input.length() == 0) {
permutations.add("");
return permutations;
}
char firstChar = input.charAt(0);
String remainingString = input.substring(1);
Set<String> words = generatePermutations(remainingString);
for (String word : words) {
for (int i = 0; i <= word.length(); i++) {
String prefix = word.substring(0, i);
String suffix = word.substring(i);
permutations.add(prefix + firstChar + suffix);
}
}
return permutations;
}
}
```
This program defines a method `generatePermutations` that takes a string `input` as input and returns a set containing all permutations of that string. In the `main` method, we call this method with `input = "abc"`, but you can change the value of `input` to find permutations of a different string.