Copy codeThe Code is as follows: 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 ";
// Replace Spaces
Src = src. replaceAll ("","");
System. out. println ("remove space character string:" + src );
List <Character> list = new ArrayList <Character> ();
Int [] bb = new int [256];
Char [] cs = src. toCharArray ();
// Reverse Order
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 --;
}
// Statistics and filter the same
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] + "");
}
}
}
String a = "abcd, efg ";
String B = ") (* & ^ % $ #@! [] {},. //;: '? <> ";
The requirement is to determine whether a character in String a appears in String B. The higher the efficiency, the better.
* Check whether some characters appear in another string.Copy codeThe Code is as follows :*
* @ 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 [2, 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 );
}
}
}
}