我想将字符数组转换为多个字符串数组的索引。 就像,
char[] c = {'a','n','i','k','s','m','r','j'};
我希望它是一个字符串,格式如“anik”,“sm”,“rj”
假设我有一个文本文件,其格式类似于“anik”,然后在新行“sm”中,依此类推。我正在逐个字符地读取它并将其存储在一个字符数组中,然后想将其转换为我的问题格式的字符串
帮我解决这个问题。 谢谢
最佳答案
如果您使用 Scanner Class 并逐字读取文件,效果会更好:
Scanner s = null;
try {
s= new Scanner(new File("translate.txt"));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
while (s.hasNextLine()) {
Scanner s2 = new Scanner(s.nextLine());
boolean b;
while (b = s2.hasNext()) {
String s1 = s2.next();
System.out.println(s1);
}
}
关于java - java中如何将char数组转换为多个字符串索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25565171/