Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can have a HashMap with key as (Questions,Answers..) and ArrayList as value</p> <pre><code>HashMap &lt;String,ArrayList&lt;String&gt;&gt; array = new HashMap&lt;String,ArrayList&lt;String&gt;&gt;(); if(array.containsKey("Question")){ array.get("Question").add(sCurrentLine.split(":")[1]); }else{ ArrayList&lt;String&gt; questions = new ArrayList&lt;String&gt;(); questions.add(sCurrentLine.split(":")[1]); array.put("Question",questions ); } </code></pre> <p>Modification In your Code</p> <pre><code>public static void OpenFile() { HashMap &lt;String,ArrayList&lt;String&gt;&gt; array = new HashMap&lt;String,ArrayList&lt;String&gt;&gt;(); int retrival = chooser.showOpenDialog(null); if (retrival == JFileChooser.APPROVE_OPTION) { try (BufferedReader br = new BufferedReader(new FileReader( chooser.getSelectedFile()))) { String sCurrentLine; while ((sCurrentLine = br.readLine()) != null) { if (sCurrentLine.equals("")) { continue; } else if (sCurrentLine.startsWith("Question")) { System.out.println(sCurrentLine.split(":")[1]); if(array.containsKey("Question")){ array.get("Question").add(sCurrentLine.split(":")[1]); }else{ ArrayList&lt;String&gt; questions = new ArrayList&lt;String&gt;(); questions.add(sCurrentLine.split(":")[1]); array.put("Question",questions ); } //add to [0] in array ArrayList } else if (sCurrentLine.startsWith("Answer")) { System.out.println(sCurrentLine.split(":")[1]); //add to [1] in array ArrayList //Do the same as above if condition with Answer as Key } else if (sCurrentLine.startsWith("Category")) { System.out.println(sCurrentLine.split(":")[1]); //add to [2] in array ArrayList } else if (sCurrentLine.startsWith("Essay")) { System.out.println(sCurrentLine.split(":")[1]); //add to [3] in array ArrayList } } } catch (Exception ex) { ex.printStackTrace(); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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