开发者

reducing the length of character array

I have a char array in string of say length开发者_Go百科 8,Its filled with 8 characters.Now i want that it should be reduced to size 5. in C we do it by putting null in end how can we do it in java?


In Java, you normally wouldn't use a character array. You'd just use a String, so it'd be something like this:

String big = "12345678";
String little = big.substring(0, 5);
// little now equals "12345"


String s = "12345678";
char[] c = new char[5];
System.arraycopy(s.toCharArray(), 0, c, 0, 5);

is one way...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜