List to Map

Hi
I have code:
Map a = new HashMap();
        for(int k=0;k<lis.size();k++){
         a.put(lis.get(k)[0], lis.get(k)[1]);
         System.out.println("L:"+lis.get(k)[0]+"\nm:"+a);
        }and lis is
  ArrayList<Object[]> lis = new ArrayList();out is:
L:siedziba
m:{siedziba=qq}
L:data
m:{data=2008-04-03, siedziba=qq}
L:regon
m:{regon=123456789, data=2008-04-03, siedziba=qq}
L:ekd
m:{ekd=7411, regon=123456789, data=2008-04-03, siedziba=qq}
L:nipp
m:{ekd=7411, regon=123456789, data=2008-04-03, nipp=, siedziba=qq}
L:peselp
m:{ekd=7411, peselp=, regon=123456789, data=2008-04-03, nipp=, siedziba=qq}
How put Object to Map that new Object insert on last position on Map ??
(example:
wrong:
m:{ekd=7411, peselp=, regon=123456789, data=2008-04-03, nipp=, siedziba=qq}
correctly:
m:{ siedziba=qq, data=2008-04-03, regon=123456789,ekd=7411, nipp=, peselp=}
Or how to set Set.iterator to get value Object from Map in the same order as in List ??
PS.
Sorry for my bad english :)

LRMK wrote:
Order of objects in the map depends on its implementation. Hash map does not have make any promises on order. To my understanding there is no map implementation that keep the insertion order in tact. So you cant do this unless you implement something on your ownLinkedHashMap does

Similar Messages

  • "Economizing" in a list of maps with identical keys (like a database table)

    Hi there!:
    I've been checking this forum for information about something like what I state in the title of this message, but haven't found such a specific case. I'm commenting my doubt below.
    I'm working with a list of maps whose keys are exactly the same in all them (they're of type String). Indeed it could be considered an extrapolation of a database table: The list contains maps which act as rows, and every map contains keys and values which represent column names and values.
    However, this means to repeat the same key values on every map and this spends memory. Right, maybe it's not such a big spent, but since the list can contains thousands of maps, I think that it would be better to choose a more "economical" way to achieve the same result.
    I had thought about building a class which stored everything as a list of lists and, internally, it mapped that String keys with the corresponding Integer indexes of every list. But then I realized that maybe I was re-inventing the wheel, because it's very probable that someone has already made that. Maybe is there a class on the Core API which allows that?
    Thank you very much for your help.

    Well, after re-reading the Java tutorial which is located in the Sun website I've came to a conclusion which I should have before, when I thought about using StringBuffers as keys of the maps instead of Strings.
    I'm so used to build Strings using literals instead of the "new String ()" constructor (just as everyone) that I had forgotten that, as it happens with any kind of object but not the primary data types, Strings are not passed to the methods by value, but by reference. The fact of them being immutable made me think that they were passed by value.
    Apart of that, my problem also was that using literals I was creating different String objects every time, despite the fact that they were equal about their content (making 400 different keys called "name" for example)
    In other words, I was doing something like this:
    // It makes a list of maps which will contain maps of boy's personal data (as if they were "rows" in a table).
    List <Map <String, Object>> listData = new ArrayList <Map <String, Object>> (listBoy.size ());
    // It loops over a list of Boy objects, obtained using EJB.
    for (Boy boy : listBoy) {
         // It makes a new map containing only the information which I'm interested on from the Boy object.
         Map <String, Object> map = new HashMap <String, Object> (2);
         map.put ("name", boy.getName ());
         map.put ("surname", boy.getSurname ());
         // It adds the map to the list of data.
         listData.add (map);
    }Well, the "problem" here (being too demanding, but I'm :P ) is that I was adding all the time new Strings objects as keys in every map. The key "name" in the first map was different from "name" in the second one and so on.
    I guess that my knowledge got messed at certain point and thought that it was impossible to use exactly the same String object in different maps (the reference, not the same value!). Thus, my idea of using StringBuffers instead.
    But thinking about it carefully, Why not to do this?:
    List <Map <String, Object>> listData = new ArrayList <Map <String, Object>> (listBoy.size ());
    // It makes the necessary String keys previously, instead of using literals on every loop later.
    String name = "name";
    String surname = "surname";
    for (Boy boy : listBoy) {
         // It uses references (pointers) to the same String keys, instead of new ones every time.
         Map <String, Object> map = new HashMap <String, Object> (2);
         map.put (name, boy.getName ());
         map.put (surname, boy.getSurname ());
         listData.add (map);
    }Unfortunately, the "hasCode" method on String is overloaded and instead of returning the typical hash code based on the single ID of the object in memory, it returns one based on its content. That way I can't make sure that the "name" key in one map refers to the same object in memory than another one. I know, I know. The common sense and the Java documentation confirm that, but had loved having an empiric way to demonstrate it.
    I guess that using "javap" and disassembling the generated bytecode is the only way to make sure that it's that way.
    I believe that it's solved now :) (if no one tells me the contrary). I still am mad at myself for thinking that Strings were passed by value. Thinking about it now it had no sense!
    dannyyates: It's curious because re-reading every answer I think that you maybe were pointing to this solution already. But the sentence "you put the +same+ string" was a little ambiguous for me and thought that you meant putting the same String as "putting the same text" (which I already was doing), not the same object reference (in other words, using a common variable). I wish we could have continued discussing that in depth. Thanks a lot for your help anyway :) .

  • Sorting in List Hash Map

    Hi All ,
    I i have the data in below format:
    Name     Age     Skill     Company
    Vass     21     Java     Zylog
    Samy     24     PB     HP
    Lee     18     ADF     CTS
    Reng     16     Java     Info
    I converted this data into java collections List<Hash Map> like this.
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.Iterator;
    import java.util.List;
    public class HashMapDemo {
        public static void main(String[] args) {
            // Create a hash map
            List<HashMap> list = new ArrayList<HashMap>();
            HashMap hm = new HashMap();
            hm.put("Name", new String("Vass"));
            hm.put("Age", new Integer(21));
            hm.put("Company", new String("Zylog"));
            hm.put("skill", new String("Java"));
            list.add(hm);
            HashMap hm1 = new HashMap();
            hm1.put("Name", new String("Samy"));
            hm1.put("Age", new Integer(24));
            hm1.put("Company", new String("HP"));
            hm1.put("skill", new String("PB"));
            list.add(hm1);
            HashMap hm2 = new HashMap();
            hm2.put("Name", new String("Lee"));
            hm2.put("Age", new Integer(18));
            hm2.put("Company", new String("CTS"));
            hm2.put("skill", new String("ADF"));
            list.add(hm2);
            HashMap hm3 = new HashMap();
            hm3.put("Name", new String("Reng"));
            hm3.put("Age", new Integer(16));
            hm3.put("Company", new String("Info"));
            hm3.put("skill", new String("Java"));
            list.add(hm3);
            Iterator i = list.iterator();
            while (i.hasNext()) {
                System.out.println(i.next());
    } As per data (table format) i want to sort the data in Column level
    how can i to achieve ?.
    List<HashMap> is type of collection is help to me?
    Any idea?
    Thanks,
    Vass Lee

    Check out Comparator, and use Google to find examples on how to use it.
    http://download.oracle.com/javase/6/docs/api/java/util/Comparator.html
    Still sorting a collection of hashmaps is a bit odd design though. I think you want to create a simple class with properties in stead of a HashMap, then implement Comparable on that class.

  • Iterate through a list containing Map items using struts

    Hi friends,
    I have a small problem. I want to iterate through a list of items, using struts.
    The list actually contains map structres for example:
    list(0)
         map(..key..value..)
         map(..key..value..)
         map(..key..value..)
    list(1)
         map(..key..value..)
         map(..key..value..)
         map(..key..value..)
    list(2)
         map(..key..value..)
         map(..key..value..)
         map(..key..value..)can I use <logic:iterate/> for this? if yes how? Because I have used this tag for list containing bean objects not Map.
    Any suggestions are much appreciated.
    Thanks,
    Vishal

    Normally, each object exposed by the iterate tag is an element of the underlying collection you are iterating over. However, if you iterate over a Map, the exposed object is of type Map.Entry that has two properties:
    key - The key under which this item is stored in the underlying Map.
    value - The value that corresponds to this key.
    So, if you wish to iterate over the values of a Hashtable, you would implement code like the following:
    <logic:iterate id="element" name="myhashtable">
    Next element is <bean:write name="element" property="value"/>
    </logic:iterate>
    Best Regards
    Maruthi

  • Iteration through a list of map entries

    hi,
    I am facing a situation in which i have to write a rule to iterate through a list of map entries within a map and again iterate for a given attribute through a map of attributes within the selected map entry.
    Can anyone throw light on any function or expression in the XPRESS language in the Identity Manager to accomplish this.
    thanx in advance,
    yashuwyah

    HI,
    I cant help you out with full code at this point. But do make use of the following to determine the equivalency between GenericObject and HashMap as shown below.
    Basic Operations
    � map.keySet() == genObj[*].name
    � map.entrySet() == genObj[*]
    � map.get(attribute) == genObj.attribute
    � map.get(attribute1).get(attribute2).get(employeeNumber) ==
    genObj. attribute1. attribute2.employeeNumber� if attribute1 indexes a list object in the preceding example ==
    genObj. attribute1[attribute2].employeeNumber� Searches
    � find the object with the attribute fullname = �John Smith� ==
    genObj[fullname=John Smith]� get John Smith�s employeeNumber == genObj[fullname=John
    Smith].employeeNumber� List Operations
    � get the names of all permanent employees ==
    genObj[employeeType=permanent].nameFor your requirements, I figure that you can iterate through the list in the beginning and assign the initial result to a <defvar>. Then use the reference of this to determine the required attributes next.
    IC.

  • Problem with list and map in GWT

    I have a problem with map and list in GWT. I need to put a map in to a list but GWT does not support ArrayList and HashMap since they are not serialized types.
    Exactly I want to create following list with out using ArrayList and HashMap
    ArrayList<HashMap<String, Object>> map = new ArrayList<HashMap<String,Object>>(); Thank you for new ideas,
    Regards

    If try to use ArrayList then I receive following exception when I make a rpc call.
    Caused by: com.google.gwt.user.client.rpc.SerializationException: Type 'java.util.ArrayList' was not included in the set of types which can be serialized by this SerializationPolicy or its Class object could not be loaded. For security purposes, this type will not be serialized.:

  • List of Map objects with html:options collection

    Hello All,
    I'm trying to get an arraylist of map objects to display dynamically as a dropdown select with html:options collection. I've spent hours on this and I haven't been able to get it working. Any ideas as to how this is done?
    Thanks,
    James

    An arraylist of Map objects?
    What is it that you want to show up in the dropdown box - all the name value pairs included in all the maps of the list?
    Assuming with a Map the "key" is what you want submitted and the "value" is what to display to the user
    Definitely sounds like a double loop structure is required. One to loop through all the maps. Another to generate all the options in each map.
    This one does it at the basic level of things
    <c:forEach var="map" items="${listOfMaps}">
      <c:forEach var="entry" items="${map}">
        <html:option value="${entry.key}">${entry.value}</html:option>
      </c:forEach>
    </c:forEach>The following might also work.
    <c:forEach var="map" items="${listOfMaps}">
      <html:options collection="map" property="key" labelProperty="value"/>
    </c:forEach>Cheers,
    evnafets

  • How are you handling your business listing on maps?

    Did you have to add it to Apple Maps or was it added by one of the Data Providers?
    Have you ever had a problem with information on it being changed?

    Audiophilia,
    Here's my latest info on how to edit/add your business to Apple Maps by country:
    Apple Maps Business Data Suppliers by Country
    I am updating this list regularly as I figure this stuff out.

  • List of Map Filter Algorithm

    I need to make a search on a List of HashMap object. The searchkey can be more than one. I need some advice on how to go about it. I really think there is a better way than doing an iteration with the list.

    How does the list fit into all of this again? It
    might be good if you posted formatted
    code that had the basic outline of your data
    structure. I mean yes I see you have a map above but
    you mentioned a List as well and I don't know what
    you have going on here exactly.
    I'll post some code to enlighten you.
    List l=new ArrayList();
    Map el;
    for (int i=0;i<10;i++) {
      el=new HashMap();
      el.put("Name", "SomeName"+i+3);
      el.put("Address", "SomeAddress"+i+1);
      el.put("Id", "SomeId"+i+2);
      l.add(el);
    Do you know what a binary search is?yes. I know what a binary search is.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Credential Store - how to list keys/maps with WLST ?

    Hi,
    How can i list the credential store's maps and keys with wlst ?
    I can see an entry of a specific map/key using listCred but i cant find which script command shows the configured maps and keys of the store.
    http://docs.oracle.com/cd/E25054_01/core.1111/e10043/csfadmin.htm#CACCGBJE
    TIA

    Hi Masood,
    Full Marks to you. I did exactly what you described and it works. It is indeed a pain  that we have to resort to coding to achieve simple tasks like this in WebUI.
    Thanks a lot for your suggestion.
    Regards,
    Shaik

  • Is Skype WiFi hotspot list on map view out yet?

    I was looking for WiFi's location list, and I found that on the pricing list of Skype WiFi page there are given the names of the hotspot providers.
    But I don't think that only name can help you to locate the place.
    What I was looking for is map view of hotspot location..
    I read somewhere that work was in progress on it.
    So is it progressed till now or shall we have to wait further?

    @Neil: Thanks for sharing, but what is really - in the case you describe - the point of using Skype Credit instead of just paying normally for the pay hotspot that WiFI Finder has brought you to? Is it much cheaper, easier etc.? If not I'lll spare myself for the inconvenience of transfering money to my Skype account (and thereby paying in advance) - and just use the pay and free hotspots that WiFi will locate for me.    Regards,Anders

  • My Address Is Not Listed In Maps

    Hi all.
    Apparently my address doesn't exist. When Maps locates me, you can see my house and street no problem, but type in the address and it doesn't exist. I've reported it via Maps 3 times since launch day but they've still not updated their database. I could understand if my house was only recently built, but it's well over 40 years old! I can't do that involves my home address, I have to set 'home' to a property near mine, which then means I can't send my details to anyone as they're incorrect. It's been more than long enough for the database to have been updated, *** is going on?!
    I'm now at the point of returning my 5 under UK consumer law as not as described/faulty.

    pjklondon wrote:
    I'm now at the point of returning my 5 under UK consumer law as not as described/faulty.
    Do whatever you'd like.  We're users here and don't really care what you do.
    Meantime, is there something else that we USERS can help you with on this technical support forum?  If so, please let us know.

  • How to get the list of installed maps in OviMaps 3...

    Is it possible somehow to get the list of maps which are downloaded and installed to OviMaps 3.03? Map loader seems not to help

    Use nokia ovi suites. This has the new map loader inside it. Once you run it, attach your phone, click on map, and it should show you a least of countries that has maps you can download for.

  • How to get Resultset in a Map or List

    Hi
    I want to store the data returned by the resultset in an array or list or map. but i dont know how to do it.
    also i need to know once stored how can i retrieve those values..
    Instead of saying
    while (rs.next()) {
    String name = rs.getString("name");
    String values = rs.getString("value");
    int id = rs.getInt("Id"); }
    i want it to be
    while(rs.next())
    { Map dataMap = new HashMap();
    dataMap.put(rs.getObject()); }
    something like [1,name1, value1
    2, name2, value2] and so on
    Does anone have any suggestions?
    I did refer to the below example, but i think there must be a simpler way
    http://forum.java.sun.com/thread.jsp?forum=48&thread=484092
    Thank you

    Check out the Jakarta DBUtils package. It can return a resultset as a Map.

  • Unusual items in 'recents' Maps list

    For some reason I keep seeing unusual addresses in the recents list on Maps. These can't be cleared using the 'clear all' button.
    The most recent unknown address appears to be Apple's European head office with the text 'From Find My iPhone' underneath. (Image link attached)
    https://www.dropbox.com/s/da49o633himbcf9/Photo%2013-10-2013%2023%2059%2004.png
    Sometimes unknown addresses appear with 'From Facebook' underneath them, which suggests that the Facebook app is placing these addresses in my recents list, even though I've never viewed them.
    After a few days they simply disappear.
    Anyone else have this issue?

    Please do not double post the threads, i answer this in your first thread, thanks
    If I help you with any inquire, thank you for click kudos in my post.
    If your issue has been solved, please mark the post was solved.

Maybe you are looking for

  • Can simulations delete previous pages in graph view

    When I run simulations with Multisim 13.0 it will add new pages to the grap view windows but after a while I will need to clear the pages with Edit->Clear pages. Is it possible when I run a simulation that the previous pages from previous simulations

  • ICC profiles missing from the menu (InDesign 6.0.4.)

    After the update to InDesign 6.0.4 icc profiles saved in Macintosh HD/Library/ColorSync/Profiles does not list in InDesign profiles menus. But they show up in Photoshop CS4. Why? I've tried to reset the InDesign's preferences folder and fixed file pe

  • Netgear CG3000 and Apple Airport

    I have a Netgear CG3000 from my cable provider and both an Apple Time Capsule and an Apple Airport Express. My Netgear router is located near my TV as the data-cable are located here. I would like to place my Time Capsule in my office, but I cannot f

  • TIPS(22) : EXPORTING TABLES BASED ON TABLESPACE NAME

    제품 : ORACLE SERVER 작성날짜 : 1996-11-12 TIPS(22) : Exporting tables based on Tablespace name ==================================================== This script allows the user to enter the tablespace name and creates a list of tables in exp format. Additi

  • VM with dynamic Memory in Bootloop

    Hey there, in a Server 2012 Cluster there is a VM with Server 2003 Ent. SP2 x86 with dynamic Memory which hangs in a bootloop. There is no Bluescreen or something like this. Change it to static memory, everything is fine. tried: - reinstalled the Int