How to add contents of char[] array to new char[] letters? - java -
i try implement hasnext() method in iterator.
public boolean hasnext() { filename = this.filecontent.getfilename(); int charlinesize = 0; scanner in = null; arraylist<character> charlist = new arraylist<> try(scanner scanner = new scanner(new bufferedreader(new filereader(filepath)))) { while (scanner.hasnextline()) { string line = scanner.nextline(); charlinesize = line.split("\\s+").length; string wordsline = line.split("\\s+").tolowercase(); charlist.addall(new arraylist<>(wordsline.chars().maptoobj(c -> (char) c).collect(collectors.tolist()))); } } catch(filenotfoundexception e) { system.out.println(e); } if (index < charlinesize) { return true; } else { return false; } } public string next() { if (hasnext()) { return charlist.get(index++); } else { return null; } } first of all, split line chars here. correct way store chars in charlist , update after scanner goes through each line?
i want specific char in next() method.
how split them chars?
second, when so, how add content of letters char[] array after each line?
you can't. once array has been created, cannot cannot change size. implies need know total amount of characters beforehand, not case.
declare array list of characters on can call array.add(char).
list<character> array = new arraylist<>();
Comments
Post a Comment