检索字符的种类
package com.swun.se;
import java.util.*;
public class TestDemo{
public static void main(String args[])throws Exception{
String str = "abcdeffffffffffffffffffff";
char[] arr = str.toCharArray();
int kinds = TestDemo.countKinds(arr);
System.out.println("有"+kinds+"种字符");
}
public static int countKinds(char[] args){
Set<Character> set = new HashSet<>();
for(int i=0;i<args.length;i++){
set.add(args[i]);
}
return set.size();
}
}
网友评论