Let's say I have an array :
char[] chars={'X','X','m','a','t','t','X','X'};
I want to create String with value "matt", so starting from chars' index 2 to 5. Is there a built-in method to achieve this, or I must do looping?
Use this String constructor, so
new String(chars,2,4);
check http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html there is a String constructor with a offset
i.e. new String(chars,2,4);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With