Note that there are some explanatory texts on larger screens.

plurals
  1. PO[java]why hashmap's data come back after I add some data eventhough I hava already clear the hashmap
    primarykey
    data
    text
    <pre><code>public class readBin { public static void main(String[] args) throws IOException{ long time1 = System.currentTimeMillis(); File targetfile = new File("d:\\d2012.bin"); FileInputStream in = new FileInputStream(targetfile); BufferedReader br = new BufferedReader(new InputStreamReader(in)); byte[] buffer = new byte[2097152]; int byteread = 0; String bufferString = ""; ArrayList&lt;HashMap&gt; arr = new ArrayList&lt;HashMap&gt;(); ArrayList arrstr = new ArrayList(); HashMap hashmap = new HashMap(); ArrayList&lt;String&gt; cttarr = new ArrayList&lt;String&gt;(); String[] strarr = new String[2]; ArrayList&lt;String&gt; valarr = new ArrayList&lt;&gt;(); //It's all init above,below comes the file reading bufferString = br.readLine(); while(bufferString != null){ //if data readed this line from the file is not "*newrecord" or "" if(!bufferString.equals("*NEWRECORD")&amp;&amp;!bufferString.equals("")){ //according to the need,make use of these data strarr = bufferString.split("="); switch (strarr[0].trim()) { case "UI": hashmap.put(strarr[0].trim(), strarr[1].trim()); break; case "MH": hashmap.put(strarr[0].trim(), strarr[1].trim()); break; case "AQ": String[] valuearr = strarr[1].split(" "); hashmap.put(strarr[0], valuearr); break; case "ENTRY": bufferString = bufferString.split("\\|")[0].toString(); //if key named ENTRY has already existed,update the data if (hashmap.containsKey(strarr[0].trim())) { ArrayList&lt;String&gt; templist = ((ArrayList&lt;String&gt;)hashmap.get(strarr[0].trim())); templist.add(bufferString.split("=")[1].trim()); hashmap.put(strarr[0].trim(), templist); //or insert it } else { cttarr.add(bufferString); hashmap.put(strarr[0].trim(),cttarr); } break; case "MS": hashmap.put(strarr[0].trim(), strarr[1].trim()); break; case "MN": //as ENTRY do if (hashmap.containsKey(strarr[0].trim())) { ArrayList&lt;String&gt; templist = ((ArrayList&lt;String&gt;)hashmap.get(strarr[0].trim())); templist.add(strarr[1].trim()); hashmap.put(strarr[0].trim(), templist); } else { cttarr.add(strarr[1].trim()); hashmap.put(strarr[0].trim(),cttarr); } break; default: break; } } else if(hashmap.size() != 0) { //if it equals to *newrecord or "",init the hashmap again arr.add(hashmap); hashmap = new HashMap(); } bufferString = br.readLine(); if (bufferString == null) { arr.add(hashmap); } } ArrayList arrresult = arr; long time2 = System.currentTimeMillis(); System.out.println(time2-time1); String ui = (String) arr.get(0).get("MH"); ArrayList&lt;String&gt; entrys = (ArrayList&lt;String&gt;) arr.get(0).get("ENTRY"); int len = arr.size(); System.out.println(ui); System.out.println(len); } public String getbs(){ return ""; } } </code></pre> <p>I want to iterate the data from the file and add them to the hashmap,after updating the hashmap to the arrayList,init the hashmap again.but from the result ,it seems the data in the hashmap wont clear.</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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