public class Solution {
public static void main(String[] args) {
String a="asdfsdsasd";
String max ="";
String realmax="";
List<String> list = new ArrayList<String>();
for (int i = 0; i < a.length(); i++) {
for (int j = i+1; j <= a.length(); j++) {
max=a.substring(i,j);
Set<Character> set=new HashSet<Character>();
for (char str : max.toCharArray()) {
set.add(str);
}
if(set.size()==max.length()) {
realmax=max;
list.add(realmax);
}
}
}
HashSet<String> set1= new HashSet<String>(list);
System.out.println(set1);
int maxnum=1;
for (String string : set1) {
if(string.length()>maxnum) {
maxnum=string.length();
}
}
System.out.println(maxnum);
for (String string : set1) {
if(string.length()==4) {
System.out.println(string);
}
}
}
}
运行结果: