I'm working on a small side project and need to join an array from one element to another - so if my array is: {"1","2","3","4","5"}
I would like my output to be in the form of startingElement|elementsInBetween|endingElement
my code for this section looks like this:
int lastTwo = Integer.parseInt(String.join("",numberArray[numberArray.length-2],
numberArray[numberArray.length-1]))
This works for when I want the last two digits (in this case Strings needed to be converted to int) but I now need to join all elements except the last one.
I wrote up a solution which involved making a new array comprised of the elements of the original array minus the last element, and then using the String.join method on the new array. But I feel like this is horribly inefficient.
Edit: Here is the testing solution I came up with:
String[] test = {"a", "b", "c","d","e","f"};
String[] test1 = new String[test.length-2];
for(int i =0; i< test1.length; i++){
test1[i] = test[i];
}
as I stated, this does technically do what I want, but I feel like a cleaner solution is available...