Note that there are some explanatory texts on larger screens.

plurals
  1. POStruggling with methodizing my main program (a method that has a LinkedList as input and output specifically). Where am i going wrong with this?
    text
    copied!<p>first off thank you for the pointer that something.endsWith doesn't do what i was expecting it to do yesterday. Now the reason i would like to borrow your brains today is the following; i have written my program and it does exactly what i need but it's all in a chunky 'main' so i wanted to shift some parts of the code to methods to make it more readable/mantainable and i am struggling with a method that works with a LinkedList.</p> <p>The code as part of the main program was as follows:</p> <pre><code>/* Variable definition */ List mzList = new LinkedList(); mzList = new ArrayList(); /* Reading the input file */ try { FileInputStream a_stream = new FileInputStream("./precursors"); DataInputStream a_in = new DataInputStream(a_stream); BufferedReader a_reader = new BufferedReader(new InputStreamReader(a_in)); String a_line; while ((a_line = a_reader.readLine()) != null) { if (a_line.equals("---")) { /* Do Nothing... */ } else { mzList.add(a_line); } } /* ends the loop that reads input file */ a_in.close(); */ } </code></pre> <p>I have been trying to write this into a method as follows:</p> <pre><code>public static LinkedList filereader (String filename, LinkedList someList) { FileInputStream input = new FileInputStream(filename); DataInputStream in = new DataInputStream(input); BufferedReader reader = new BufferedReader(new InputStreamReader(in)); String line; while ((line = reader.readLine()) != null) { if (line.equals("---")) { /* Do Nothing... */ } else { someList.add(line); } } in.close(); return(someList); } </code></pre> <p>I would then attempt to call this in the main program as follows:</p> <pre><code>mzList = class.filreader("precursor",mzList); </code></pre> <p>which gives me a bunch of problems, obviously i am doing something stupid and i beg forgiveness for my harassing you all with this problem but i am quite new to Java and searching through the other 'questions' didn't really help me solve my problem.</p> <p>Kind Regards, Bas Jansen</p> <p>PS: Edited some blatant typo's and formatting errors</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload