Interview Question
Java DevelopersCountry: India
Interview Type: Written Test
public String[] split(String str, String splitChar){
char[] strArray = str.toCharArray();
char[] tempCharArray = new char[strArray.length];
List<String> temp = new ArrayList<String>();
int j = 0;
for(int i=0; i< strArray.length; i++){
if(strArray[i] != splitChar.toCharArray()[0]){
tempCharArray[j++] = strArray[i];
} else {
temp.add(String.valueOf(tempCharArray));
tempCharArray = new char[strArray.length];
j = 0;
}
}
temp.add(String.valueOf(tempCharArray));
return temp.toArray(new String[temp.size()]);
}
public String[] split(String str, String splitChar){
- tcbhardwaj October 28, 2015char[] strArray = str.toCharArray();
char[] tempCharArray = new char[strArray.length];
List<String> temp = new ArrayList<String>();
int j = 0;
for(int i=0; i< strArray.length; i++){
if(strArray[i] != splitChar.toCharArray()[0]){
tempCharArray[j++] = strArray[i];
} else {
temp.add(String.valueOf(tempCharArray));
tempCharArray = new char[strArray.length];
j = 0;
}
}
temp.add(String.valueOf(tempCharArray));
return temp.toArray(new String[temp.size()]);
}