Java 如何在 tokenizer 中将 char 转换为 String
How to convert char to String in tokenizer in Java
正在尝试将以逗号分隔的文件读取到数组中,但不确定如何将 party 变成字符串以使用 tokenizer
for(int i = 0; i < s.length; i++) {
String str = scan.nextLine();
StringTokenizer st = new StringTokenizer(str, ",");
//String [] tokens = str.split(",");
String name = st.nextToken();
String abbreviation = st.nextToken();
long population = Long.parseLong(st.nextToken());
String govName = st.nextToken();
char party = st.nextToken();
int ageWhenElected = Integer.parseInt(st.nextToken());
s[i] = new State(name, abbreviation, population, govName ,party, ageWhenElected);
您可以使用逗号作为分隔符加入您的字符串数组
StringUtils.join(strArray, ",");
尝试
char party = st.nextToken().charAt(0);
正在尝试将以逗号分隔的文件读取到数组中,但不确定如何将 party 变成字符串以使用 tokenizer
for(int i = 0; i < s.length; i++) {
String str = scan.nextLine();
StringTokenizer st = new StringTokenizer(str, ",");
//String [] tokens = str.split(",");
String name = st.nextToken();
String abbreviation = st.nextToken();
long population = Long.parseLong(st.nextToken());
String govName = st.nextToken();
char party = st.nextToken();
int ageWhenElected = Integer.parseInt(st.nextToken());
s[i] = new State(name, abbreviation, population, govName ,party, ageWhenElected);
您可以使用逗号作为分隔符加入您的字符串数组
StringUtils.join(strArray, ",");
尝试
char party = st.nextToken().charAt(0);