本文介绍了Java中字符串字符的结尾的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!
问题描述
我正在解决一个简单的问题:
I was solving an easy question :
在Java中删除字符数组的某些字符,想法很简单:
Remove certain characters of a character array in Java , the idea is straightforward :
static void remove_char(char[] arr, char c){
int r = 0;
for (int i = 0 ; i < arr.length ; i++){
if (arr[i] == c){
r++;
continue;
}
arr[i - r] = arr[i];
}
arr[arr.length - r] = ' '; // ??
return;
}
我想放置一个 结束字符
,它表示当我们想要生成字符串时不必考虑数组的其余部分,例如,使用 new String(arr)
I want to put an ending character
which signals that the rest of the array doesn't have to be considered when we want to, for example, generate a string using new String(arr)
Java 中有这样的字符吗?(我猜在 C
中是