I am not sure about what your need is.But i am sure anyone of the below methods will surely help you..
1.Covert String With Comma To A ArrayList
Program:
import java.util.Arrays;
....
String name="java,php,c";
List<String> list=Arrays.asList(name.split(","));
System.out.println(" "+list);
OutPut:
[java, php, c]
2.Covert ArrayList To StringArray
Here we can convert the same arraylist that we got in 1st method to string array.
Program:
String []names=list.toArray(new String[list.size()]);
for(String s:names){
System.out.println(""+s);
}
OutPut:
java
php
c
3.Covert ArrayList To Comma Seperated String
Here we can convert the same arraylist that we got in 1st method to string array.
For this you need To add commons-lang3-3.2.1.jar into your classpath or project libarary.
You can Download The commons-lang3-3.2.1.jar (HERE)
Program:
import org.apache.commons.lang3.StringUtils;
.....
String name=StringUtils.join(list, ",");
System.out.println("name="+name);
OutPut:
name=java,php,c
4.Updated Program
This might me the method that you needed
public String[] getMerged(String host, String port, String filesToCopy) {
String files[] = filesToCopy.split(",");
String[] merged = new String[(2 + files.length)];
merged[0] = host;
merged[1] = port;
System.arraycopy(files, 0, merged, 2, files.length);
return merged;
}
Check out these methods and notify me if your need is something other than these methods..