如何拆分 arrayList String SCHOOLWORK BALCONY INSIST SALTPETER BOLTON KITSCHY CLIENTELE
我想将这些词拆分为“SCH”、“OOL”、“WO”、“RK”。
这是我的代码
import java.io.File;
import java.util.ArrayList;
public class HW2 {
public static ArrayList<String> getTiles(ArrayList<String> input_list_of_strings) {
// create a substring by go through the loop first, then .... (instruction)
Object[] subString = new Object[input_list_of_strings.size()];
for (int i = 0; i < input_list_of_strings.size(); i++) {
subString[i] = input_list_of_strings.get(i);
// test just want to see if subString get all String
// System.out.println(subString[i]);
String delim=" ";
String[] splitstrings = ((String) subString[i]).split(delim);
for (int j = 0; j < splitstrings.length; j++) {
splitstrings[j] +=delim;
System.out.println(splitstrings[j]);
}
}
return input_list_of_strings;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
ArrayList<String> input_words = new ArrayList<String>();
input_words.add("SCHOOLWORK");
input_words.add("BALCONY");
input_words.add("INSIST");
input_words.add("SALTPETER");
input_words.add("BOLTON");
input_words.add("KITSCHY");
input_words.add("CLIENTELE");
System.out.print(getTiles(input_words));
}
}
谢谢...