简体   繁体   中英

What does the below code do? Is it a 2D array?

char[] removechararray=removecharacterstring.toCharArray();

boolean[]  tempBoolean = new boolean[128];

tempBoolean[removechararray[start]]=true;

reremovechararray[start] returns and char which is casted to int and used as index for the tempBoolean array.

Example:

char[] removechararray="abc".toCharArray();
boolean[]  tempBoolean = new boolean[128];
tempBoolean[removechararray[0]]=true;

The above code assigns true to the 98 th element of the tempBoolean array, because removechararray[0] returns an a which is casted to its acsii value 97. It's a bit confusing, but you can cast char to int and backwards and do operations like this:

int c = 'b' + 1;
System.out.println(c + " " + (char) c); // output: 99 c

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM