I'm trying to get this program's groupPairs function to take the six Strings in an initial String array [One,Two,Three,Four,Five,Six] and create a new String array of half the size (3) with the original six Strings grouped sequentially in pairs [OneTwo,ThreeFour,FiveSix], and then return that resulting new String[] to the main method.
import java.util.*;
public class Application
{
static String[] groupPairs(String[] array)
{
String[] newArray = new String[(array.length)/2];
int count=0;
for(String string:newArray)
{
newArray[count]=array[count].append(array[count+1]);
count=count+2;
}
return newArray;
}
public static void main(String args[]) //main method, don't worry about this
{
String[] list = new String[5];
list[0]="One";
list[1]="Two";
list[2]="Three";
list[3]="Four";
list[4]="Five";
list[5]="Six";
String[] list2 = groupPairs(list);
}
}
When trying to compile the program, I get this error:
Application.java:11: cannot find symbol
symbol : method append(java.lang.String)
location: class java.lang.String
newArray[count]=array[count].append(array[count+1]);
^
Any ideas on how to fix this line so that my new array will have concatenated pairs of the original String[] values would be greatly appreciated!