import java.util.ArrayList;
import java.util.List;
public class Test2 {
/**
* @param args
*/
public static void main(String[] args) {
String src = "A B C D E B C";
//替换掉空格
src = src.replaceAll(" ", "") ;
System.out.println("去除空格后字符串:" + src) ;
List<Character> list = new ArrayList<Character>() ;
int[] bb = new int[256];
char[] cs = src.toCharArray();
//倒序
int mid = cs.length / 2 ;
int idx = cs.length -1 ;
for (int i = 0; i < mid ; i++){
char tmp = cs[i] ;
cs[i] = cs[idx] ;
cs[idx] = tmp ;
idx-- ;
}
//统计,并且过滤相同的
for (char c : cs) {
if (bb[c] <1) {
list.add(c) ;
}
bb[c] = bb[c] + 1;
}
System.out.println();
for (int i = 0; i < list.size(); i++){
System.out.print(list.get(i)) ;
}
System.out.println() ;
for (int i = 0; i < list.size(); i++){
char c = list.get(i) ;
System.out.println(c + " " + bb[c] + "次") ;
}
}
}
http://blog.csdn.net/java2000_net/article/details/5250740
String a = "abcd,efg";
String b = ")(*&^%$#@![]{},.//;:'? <>";
要求是判断String a 里有没有哪个字符在String b里出现 ,效率越高越好
* 查找某些字符是否在另一个字符串里出现
- *
- * @author Java人(java2000.net)
- */
- public class Test {
- /**
- * @param args
- */
- public static void main(String[] args) {
- String a = "abcd,efg";
- String b = ")(*&^%$#@![]{},.///;:'? <>";
- byte[] bb = new byte[256];
- char[] cs = b.toCharArray();
- for (char c : cs) {
- bb[c] = 1;
- }
- cs = a.toCharArray();
- for (char c : cs) {
- if (bb[c] == 1) {
- System.out.println(c);
- }
- }
- }
- }