How to count characters in Java and how to reverse order non-identical characters _java

Source: Internet
Author: User
Copy Code code 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 space
src = Src.replaceall ("", "");

System.out.println ("Remove the space after the string:" + src);
list<character> list = new arraylist<character> ();
int[] bb = new int[256];
Char[] cs = Src.tochararray ();

Reverse
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 filters 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] + "Times");
}

}
}

String a = "ABCD,EFG";
String B = ") (*&^%$#@![] {},.//;:'? <> ";
To be to determine if any character in string a appears in string B, the higher the efficiency the better

* Find out if certain characters appear in another string
Copy Code code as follows:

*
* @author java person (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);
}
}
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.