Ok so I'm trying to create a method that takes 2 strings, the second string argument is the string to be removed from the first string argument. I can't figure out what's wrong with my code? Any help? Thanks.
Example of what I'm trying to do: if you pass in "a,b,c" as the first argument and "," as the second argument, you get "abc" returned.
public List<String> split(String string, String delimiter){
//create and init arraylist.
List<String> list = new ArrayList<String>();
//create and init newString.
String newString="";
//add string to arraylist 'list'.
list.add(string);
//loops through string.
for(int i=0;i<string.length();i++){
//stores each character from string in newString.
newString += string.charAt(i);
}
newString.replace(delimiter, "");
//remove string from arraylist 'list'.
list.remove(string);
//add newString to arraylist 'list'.
list.add(newString);
return list;
String.split(docs.oracle.com/javase/1.5.0/docs/api/java/lang/…)?a,b,cis a string and you want stringabc, why cann't you just doyourString.replaceAll(secondArg, "");List, shouldn't it be aString