我有一个String[]像这样的值:
public static final String[] VALUES = new String[] {"AB","BC","CD","AE"};
Run Code Online (Sandbox Code Playgroud)
鉴于String s,有没有一种好的方法来测试是否VALUES包含s?
所以我知道String#codePointAt(int),但它是由char偏移索引,而不是由代码点偏移索引.
我正在考虑尝试这样的事情:
String#charAt(int)得到char的指数char在高代理范围内
String#codePointAt(int)获取代码点,并将索引增加2char值作为代码点,并将索引递增1但我担心的是
char值或一个值我创建了一种方法来查找字符串中最常见的字符:
public static char getMax(String s) {
char maxappearchar = ' ';
int counter = 0;
int[] charcnt = new int[Character.MAX_VALUE + 1];
for (int i = 0 ; i < s.length() ; i++)
{
char ch = s.charAt(i);
// increment this character's cnt and compare it to our max.
charcnt[ch]++ ;
if (charcnt[ch] >= counter)
{
counter = charcnt[ch];
maxappearchar = ch;
}
}
System.out.println("the max char is " +maxappearchar + " and displayed " +counter+ " times");
return …Run Code Online (Sandbox Code Playgroud)