Question

So i have a string and an array of characters and what i want to do is make a string with some characters between two positions of this array.

Ex. If Arr = {a,b,c,d,e,f} I want Str= "bcde"

Was it helpful?

Solution

You can use the String(char[], int, int) constructor:

char[] arr = { 'a', 'b', 'c', 'd', 'e', 'f' };

int start = 1, end = 4;

System.out.println(new String(arr, start, end - start + 1));
bcde
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top