I have a issue i can’t get it to work now let going to the point a explain in the code thanks.
This is my class: what I want to do is insert the Integers sort the list and buffer writer in a column with out coma. Now I getting this:
[1110018, 1110032, 1110056, 1110059, 1110063, 1110085, 1110096, 1110123, 1110125, 1110185, 1110456, 1110459]
I want like this:
111xxxxx
111xxxx
xxxx…….
I can’t do it in single array, have to be in ArrayList.
This is my collecting:
list.addNumbers(numbers);
list.display();
This is my writer: Is buffered
coma.write(“\n”+list.display());
coma.flush();
**public class IdCount {
private ArrayList properNumber = new ArrayList<>();
public void addNumbers(Integer numbers) {<br/>
properNumber.add(numbers);**<br/>
Collections.sort(properNumber);
}
public String display() {
(I try .toString() Not work)
return properNumber.toString();
}**
My second issue is LineNumberReader: This is my collecting and my writing:
try {
Reader input = new BufferedReader( new FileReader(inputFile));
try (Scanner in = new Scanner(input)) {
while (in.hasNext()) {
(More Code)
asp = new LineNumberReader(input);
int rom = 0;
while (asp.readLine()!=null){<br/>
rom++;<br/>
}
System.out.println(rom);<br/>coma.write(rom);<br/>
This one not write anything an my System Print give me only 12 0 in column.
Thank you for the help in advances. Any help it will appreciate.
I want like this:
111xxxxx
111xxxx
xxxx…….
Then in write your display method as follows:
Explanation:
What you were doing :
return properNumber.toString();will return a string that contains all values insideproperNumbercomma-seperated. so thats why you were getting that output.What I have done
Made a
StringBuilderobject so that I can temporarily store the strings before returning all the values.Then I made a iterator that iterates through
properNumberand then append each entry to theStringBuilderobject and appending\nafter it.Finally when the iterator completes meaning I have added all entries inside
properNumberinStringBuilderobjectsb. So now I will return the content ofsbasStringusingsb.toString()method.