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...
精彩评论