String SomeLongString = JavaAPIMethodFor (String[] strings, String delimiter);
Or this could work as well:
String SomeLongString = JavaAPIMethodConvertingArrayWithDelimeter (String[] strings, char delimiter)
I wanted to join strings into a larger string, but this is simply useless. I am aware that I could append all the data into a string using Arrays.toString(Object someString) then adjust the string, removing unwanted characters. But that's not really efficient, building something, only to rebuild it. So looping through the String[] and adding my character[s] between each element is probably the way to go:
import static org.junit.Assert.*;
import org.junit.Test;
public class DelimetedString {
private String delimitedString(String [] test, String delimiter){
StringBuilder result = new StringBuilder();
int counter = 0;
if(test.length > counter){
result.append(test[counter++]);
while(counter < test.length){
result.append(delimiter);
result.append(test[counter++]);
}
}
return result.toString();
}
@Test
public void test() {
String [] test = new String[]
{"cat","dog","mice","cars","trucks","cups","I don't know", "anything!"};
String delimiter = " |...| ";
assertEquals("DelimitedString misformed",
"cat |...| dog |...| mice |...| cars |...| trucks "
+"|...| cups |...| I don't know |...| anything!",
delimitedString(test, delimiter));
}
}
What I wanted was something to put together a string after using a tokenizer. I abandoned that Idea, since it's probably more cumbersome then it's worth. I chose to address a Sub-Strings from within the larger String, I included the code for that, in an "answer".
What I was asking is - Does the java API have an equivalent function as the delimitedString function? The answer from several people seems to be no.