Note that there are some explanatory texts on larger screens.

plurals
  1. POarraylist nor getting store in hashmap
    primarykey
    data
    text
    <p>i m parsing xml in which particular designation contaion list of staff... so while parsing i usee hashmap to store value.I continueously add staffdata in arraylist and when i found end element tag i put that arraylist object in HashMap and clear Arraylist to store next data.</p> <p>but when i print hashmap ,i found only key in hashmap there is no arraylist at all...</p> <p>if i dont clear arraylist after puting arraylist in hashmap then values are found in hashmap...but all values are come together..so i must have to clear arraylist after put arraylist in hash map...</p> <pre><code>**HERE IS MY CODE OF XML PARSING** package com.example; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import org.xml.sax.Attributes; import org.xml.sax.SAXException; import org.xml.sax.helpers.DefaultHandler; public class StaffXmlHandler extends DefaultHandler { static int totalSection=0; static HashMap&lt;String,ArrayList&lt;Staff&gt;&gt; staffListWithDesignation=new HashMap&lt;String,ArrayList&lt;Staff&gt;&gt;(); ArrayList&lt;Staff&gt; staffList=new ArrayList&lt;Staff&gt;(); String designationName; public static HashMap&lt;String,ArrayList&lt;Staff&gt;&gt; getStaffListWithDesignation() { return staffListWithDesignation; } public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { if(localName.equals("designation")) { designationName= attributes.getValue("name"); System.out.println("=====================&gt;&gt;&gt;&gt;Designation="+designationName); } else if (localName.equals("staff")) { //System.out.println("======&gt;&gt;&gt;&gt;fetching data from staff"); String employeeName = attributes.getValue("name"); String employeeEmail=attributes.getValue("email"); String employeePost=attributes.getValue("designation"); String employeePhone=attributes.getValue("phone"); Staff s=new Staff(); s.setEmployeeName(employeeName); s.setEmployeeEmail(employeeEmail); s.setEmployeePhone(employeePhone); s.setEmployeePost(employeePost); staffList.add(s); } } @Override public void endElement(String uri, String localName, String qName) throws SAXException { /** set value */ if (localName.equalsIgnoreCase("designation")) { // Staff[] s=new Staff[staffList.size()]; // System.out.println("=========================="+designationName+"======================="); // for(int i=0;i&lt;staffList.size();i++) // { // System.out.println("=====Record "+(i+1)+"====="); // s[i]=new Staff(); // s[i]=staffList.get(i); // System.out.println("Name:"+s[i].getEmployeeName()); // System.out.println("email:"+s[i].getEmployeeEmail()); // // // } ArrayList&lt;Staff&gt; temp=staffList; staffListWithDesignation.put(designationName, temp); staffList.clear(); designationName=null; } } public void endDocument () { System.out.println("==================End Element tag"); Iterator&lt;String&gt; iterator =staffListWithDesignation.keySet().iterator(); while (iterator.hasNext()) { String key = (String) iterator.next(); System.out.println("=====&gt; " + key + "======" + StaffXmlHandler.staffListWithDesignation.get(key)); } } @Override public void characters(char[] ch, int start, int length)throws SAXException { } } </code></pre> <p>IN ABOVE CODE, IN COMMENTED LINE IF I CHECK TO SEE WHEATHER ARRAYLIST CONTAIN DAA OR NOT THEN IT SHOWS ME DATA BUT DONT KNOW WHY IT IS NOT STORE IN HASHMAP.....</p> <p>PLS GIVE ME SOME SOLUTION...</p> <p>THANKS IN ADVANCE</p>
    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.
 

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