I am having some difficulty in understanding how to write the below piece of code using String or char[] in Java.
void xyz(char *a, int startIndex, int endIndex)
{
int j;
for (j = startIndex; j <= endIndex; j++)
{
doThis((a+startIndex), (a+j));
xyz(a, startIndex+1, endIndex);
}
}
Here char *a points to the starting location of the char name[]
The above are just some random functions, but I just want the logic of how to use char* and character index char[] in Java
Based on the rephrased question from the comment thread:
You cannot change the characters of a Java
String. If you need to modify a sequence of characters, useStringBuilder, which supportssetCharAt(int, char),insert(int, char), andappend(char). You can usenew StringBuilder(myString)to convert aStringto aStringBuilder, andstringBuilder.toString()to convert back.This is perfectly legit Java code — it’s not code smelly, it’s just the way you work with mutable character sequences.