Yes, the constructor string with offset and length is used.
String(char[] value, int offset, int count) new String(data,0,3)
Now, if the exact value is unknown, you can write a utility method to fix the array. Or use trim() to trim the trailing characters.
public static char[] getNotMessedUpArray(char[] messedUp) { int messedUpIndex = messedUp.length; for (int i = 0; i < messedUp.length; i++) { if (messedUp[i] <= ' ') { System.arraycopy(messedUp, i + 1, messedUp, i, messedUp.length - i - 1); } } for (int i = 0; i < messedUp.length; i++) { if (messedUp[i] <= ' ') { messedUpIndex--; } } char[] notMessedUp = new char[messedUpIndex]; System.arraycopy(messedUp, 0, notMessedUp, 0, messedUpIndex); return notMessedUp; }
source share