List of keys(Strings): ArrayList, HashMap, ...

Dear all,
I would like to make a list of keys (Strings) such that each key can be appear only once in the list.
If I used ArrayList, the uniqueness of key would not garanteed.
If I used HashMap, it would fine but I did not need store any objects.
Any better solution?
Cheers.
Pengyou

> I would like to make a list of keys (Strings) such
that each key can be appear only once in the list.
If I used ArrayList, the uniqueness of key would not
garanteed.
Well you can always use the contains(...) method from the ArrayList first to see if the key already exists.
> If I used HashMap, it would fine but I did not need
store any objects.
I don't understand. An ArrayList also stores the values.

Similar Messages

  • Need to store all keys of a hashMap in to an arrayList. this is my solution

    Hello,
    I Need to store all keys of a hashMap in to an arrayList. this is my solution:
    private HashMap<String, V> x;
    ArrayList<V> xList = new ArrayList <V>(x.values());
              ArrayList<String> xKeyList = null;
              for(V currV: xKeyList){
                   xKeyList.add(currV.getKey());
    so because I couldn't figure out a way to use:
    "Set<K>      keySet()
    Returns a set view of the keys contained in this map."
    in order to create a ArrayList I decided to get an array of the Values of the hashMap and then iterate through those values and get the keys (names in my case, yes I use names as keys of the hashmap and I can get the name of my V individually)
    what do you think? was this a good approach or I could be using hashMap.keySet() in a better way?
    Thanks for all your input!
    (I'm aware that my solution would be very heavy toll on performance for very large maps~ that's why i'm here :D)

    malcolmmc wrote:
    You can just do
    List<K> copyOfKeys = new ArrayList<K>(x.keySet());A Set is a Collection and that's what the constructor of ArrayList takes.Yup, that works for me:
    import java.util.ArrayList;
    import java.util.List;
    import java.util.Map;
    import java.util.HashMap;
    public class Test {
        public static <K, V> List<K> keyList(Map<K, V> map) {
            return new ArrayList<K>(map.keySet());
        public static void main(String[] args) {
            Map<String, Integer> m = new HashMap<String, Integer>();
            m.put("one", 1);
            m.put("two", 2);
            m.put("three", 3);
            List<String> keyList = keyList(m);
            System.out.println(keyList);
    }

  • SelectMany checkbox value-binded with HashMap String,ArrayList

    Hello,
    Someone can help me please?
    Im trying to create a page with a lot of HtmlSelectManyCheckbox, and i need to value-bind then to the same Object in my BackingBean.
    First i attemped to bind all HtmlSelectManyCheckbox with a single ArrayList, but only the last SelectMany had their values inserted on the ArrayList...
    So, now im trying to bind all the HtmlSelectManyCheckbox with a HashMap<String,ArrayList>, because i would have just one object and for each entry I would have the checkboxes that were cheked in a single HtmlSelectManyCheckbox.
    Now my question: there is a way to make this work?
    my code example
    Backing bean
    private HashMap<String, ArrayList> respostaMatrizCheck = new HashMap<String, ArrayList>();
         public HashMap<String, ArrayList> getRespostaMatrizCheck() {
              return respostaMatrizCheck;
         public void setRespostaMatrizCheck(HashMap<String, ArrayList> respostaMatrizCheck) {
              this.respostaMatrizCheck = respostaMatrizCheck;and the bindings
    <h:selectManyCheckbox value="#{backingBean.respostaMatrizCheck['1'] }">
    <h:selectManyCheckbox value="#{backingBean.respostaMatrizCheck['2'] }">And the error message given when i tryed this is the following:
    javax.servlet.ServletException: ValueBinding for UISelectMany must be of type List or Array
    Any help would be welcome.
    Thanks,
    Ferry

    Has anybody solved a problem like this? I am facing the same problem and no response helped me so far.
    Here is the web code:
    <h:selectManyCheckbox value="#{processor.languages.languages1}">
         <f:converter converterId="languageConverter" />
         <f:selectItems value="#{categoryController.allLanguagesAsSelectItems}" />
    </h:selectManyCheckbox>My backing bean "processor" looks like this:
         public Map<String, List<MyObject>> getLanguages() {
              return languagesMap;
         }(The backing bean has no "setLanguages()-method" since I did not need any with Map<String, String> for example.)
    The converter I use creates a "MyObject" instance in its "getAsObject" conversion method.
    I think everything should be okay then but the exception I get after submitting the page is:
    java.lang.IllegalArgumentException: ValueBinding for UISelectMany must be of type List or Array
         org.apache.myfaces.shared_impl.renderkit._SharedRendererUtils.getConvertedUISelectManyValue(_SharedRendererUtils.java:191)
         org.apache.myfaces.shared_impl.renderkit.RendererUtils.getConvertedUISelectManyValue(RendererUtils.java:630)
         org.apache.myfaces.shared_impl.renderkit.html.HtmlCheckboxRendererBase.getConvertedValue(HtmlCheckboxRendererBase.java:308)
         javax.faces.component.UISelectMany.getConvertedValue(UISelectMany.java:308)
         javax.faces.component.UIInput.validate(UIInput.java:350)
    .....Edited by: rapthor on Oct 31, 2007 6:39 AM

  • Strings as hashmap keys

    If I use a string (a file name, for example) as the key for a hashmap put call, and then later try to retrieve the stored object using the same string, but this time hard-coded, will my object be retrieved? That is, will the dynamically loaded key and the hard-coded key be seen as the same object?
    that is ...
    image is read in from a file
    image is stored in hashmap, using filename as key
    retrieval is attempted using image title "image.gif" - is it successful?

    Do you mean this? String key = getStringSomehowSuchAsFielname();
    map.put(key, value);
    value = map.get("image.gif"); // I put with a variable but retrieve with a constant, so will it work?If that's what your'e asking, then yes, it will work. As long as the object that you use for a key properly overrides equals and hashCode, then it can be used as a key in a Map.
    "Properly overrides..." means that the state of the object is used the way you want it to be used for determining equality. In the case of java.lang.String, they're overriden the way you'd expect--i.e., using the sequence of characters in the string to determine equality.
    Make sense?

  • Please Help::How to display a Map with LIsts as Keys and Values using JSTL

    Hi,
    I need some assistance on how to display a Map in JSP using struts or core JSTL. I have a HashMap which has a List of keys and each key maps to a value of an ArrayList.i.e I have an ArrayList of taxCodes and each taxCode maps to a value of taxDetails which is an ArrayList of details for for that particular taxCode. I have some trouble to display each taxCode then display taxDetails for each taxCode. Here is my code below:
    OrderDetails.java
    package orderitems;
    import java.sql.*;
    import java.util.*;
    public class OrderDetails {
        private LineOder lineOrder;
        private Map lineItems;
        //returns an item number, key_item, from its unique keys
        public int getItemNumber(int key_item, String key_year,
                String key_office,String key_client,String key_company){
            Connection conn = null;
            Statement stat = null;
            ResultSet rst = null;
            int itmNum = 0;
             * key_item a unique number for an item.
             * key_year,key_office,key_client,key_company unique keys
             * for each order where this key_item is taken
             * from.
            String select = "SELECT key_item FROM "+
                    Constants.WEB_TABLE +" WHERE key_item = " + key_item +
                    " AND key_year = '" + key_year + "'" +
                    " AND key_office = '" + key_office + "'" +
                    " AND key_client = '" + key_client + "'" +
                    " AND key_company = '" + key_company +"'";
            DbConnection dbConn = new DbConnection();
            try {
                conn = dbConn.getDbConnection(Constants.WEB_JNDI);
                stat = conn.createStatement();
                rst = stat.executeQuery(select);
                if(rst.next()){
                    itmNum = Integer.parseInt(rst.getString("key_item"));
            } catch (SQLException ex) {
                ex.printStackTrace();
            } finally{
                SQLHelper.cleanUp(rst, stat, conn);
            return itmNum;
        //get a list of item number(item codes)
        public List getAllItemNumbers(String key_year,
                String key_office,String key_client,String key_company){
            List itemNumbers = new ArrayList();
            LineItem itemNumber = null;
            Connection conn = null;
            Statement stat = null;
            ResultSet rst = null;
            String select = "SELECT key_item FROM "+ Constants.WEB_TABLE +
                    " WHERE key_year = '" + key_year + "'" +
                    " AND key_office = '" + key_office + "'" +
                    " AND key_client = '" + key_client + "'" +
                    " AND key_company = '" + key_company + "'";
            DbConnection dbConn = new DbConnection();
            try {
                conn = dbConn.getDbConnection(Constants.WEB_JNDI);
                stat = conn.createStatement();
                rst = stat.executeQuery(select);
                while(rst.next()){
                    itemNumber = new LineItem();
                    itemNumber.setKey_item(Integer.parseInt(rst.getString("key_item")));
                    itemNumbers.add(itemNumber);
            } catch (SQLException ex) {
                ex.printStackTrace();
            } finally{
                SQLHelper.cleanUp(rst, stat, conn);
            return itemNumbers;
        //get a list of tax codes
        public List getAllTaxCodes(int key_item, String key_year,
                String key_office,String key_client,String key_company){
            Connection conn = null;
            Statement stat = null;
            ResultSet rst = null;
            ItemTax taxCode;
            List taxCodes = new ArrayList();
            int itemNum = getItemNumber(key_item, key_year,
                    key_office,key_client,key_company);
            String select = "SELECT key_tax_code FROM "+
                    Constants.WEB_TABLE +" WHERE key_item = " + itemNum +
                    " AND key_year = '" + key_year + "'" +
                    " AND key_office = '" + key_office + "'" +
                    " AND key_client = '" + key_client + "'" +
                    " AND key_company = '" + key_company +"'";
            DbConnection dbConn = new DbConnection();
            try {
                conn = dbConn.getDbConnection(Constants.WEB_JNDI);
                stat = conn.createStatement();
                rst = stat.executeQuery(select);
                while(rst.next()){
                    taxCode = new ItemTax();
                    taxCode.setKey_tax_code(rst.getString("key_tax_code"));
                    taxCodes.add(taxCode);
            } catch (SQLException ex) {
                ex.printStackTrace();
            } finally{
                SQLHelper.cleanUp(rst, stat, conn);
            return taxCodes;
        /////This methode returns a Map which am trying to display in JSP
        //use tax code to get tax details
        public Map getItemTaxDetails(String key_year,String key_office,
                String key_client,String key_company,int key_item){
            ItemTax taxDetail = null;
            List taxDetails = new ArrayList();
            List itemTaxCodes = new ArrayList();
            Map itemTaxDetails = new HashMap();
            Connection conn = null;
            Statement stat = null;
            ResultSet rst = null;
            //get a list of all tax codes of an item with a
            //given item number
            itemTaxCodes = getAllTaxCodes(key_item,key_year,
                    key_office,key_client,key_company);
            DbConnection dbConn = new DbConnection();
            try {
                conn = dbConn.getDbConnection(Constants.WEB_JNDI);
                stat = conn.createStatement();
                for(Iterator taxCodeIter= itemTaxCodes.iterator(); taxCodeIter.hasNext();){
                    ItemTax itemTaxCode = (ItemTax)taxCodeIter.next();
                    String taxCode = itemTaxCode.getKey_tax_code();
                    String select = "SELECT tax_type,tax_value," +
                            "tax_limit_val FROM "+ Constants.WEB_TABLE +
                            " WHERE key_item = "+ key_item +
                            " AND key_year = '" + key_year + "'" +
                            " AND key_office = '" + key_office + "'" +
                            " AND key_client = '" + key_client + "'" +
                            " AND key_company = '" + key_company +"'" +
                            " AND key_tax_code = '" + taxCode + "'";
                    rst = stat.executeQuery(select);
                    while(rst.next()){
                        taxDetail = new ItemTax();
                        //records to be displayed only
                        taxDetail.setKey_item(Integer.parseInt(rst.getString("key_item")));
                        taxDetail.setTax_value(rst.getString("tax_value"));
                        taxDetail.setTax_limit_val(Float.parseFloat(rst.getString("tax_limit_val")));
                        //////other details records ommited//////////////////////////
                        taxDetails.add(taxDetail);////An ArrayList of taxDetails for each taxCode
                     * A HashMap which has all taxCodes of an item as its keys
                     * and an ArrayList of taxdetails as its values.
                     * I return this for display in a JSP.
                    itemTaxDetails.put(taxCode,taxDetails);
                System.out.println();
                System.out.println("*********CONSOLE OUTPUT*************");//display on console
                Set set = itemTaxDetails.keySet();
                Iterator iter = set.iterator();
                System.out.println("Key\t\tValue\r\n");
                while (iter.hasNext()) {
                    Object taxCode=iter.next();
                    Object details=itemTaxDetails.get(taxCode);
                    System.out.println(taxCode +"\t" + details);
                System.out.println("************************************");
            } catch (SQLException ex) {
                ex.printStackTrace();
            } finally{
                SQLHelper.cleanUp(rst, stat, conn);
            return itemTaxDetails;
        //details of an item with all its taxes
        public List getAllItemDetails(String key_year,
                String key_office,String key_client,String key_company){
            List lineItems = new ArrayList();
            List itemNumbers = new ArrayList();
            Map taxDetails = new HashMap();
            LineItem item = null;
            Connection conn = null;
            Statement stat = null;
            ResultSet rst = null;
            //A list of all item numbers in the declaration
            itemNumbers = getAllItemNumbers(key_year,
                    key_office,key_client,key_company);
            DbConnection dbConn = new DbConnection();
            try {
                conn = dbConn.getDbConnection(Constants.WEB_JNDI);
                stat = conn.createStatement();
                for(Iterator itemIter= itemNumbers.iterator(); itemIter.hasNext();){
                    LineItem itemNum = (LineItem)itemIter.next();
                    int itemNumber = itemNum.getKey_item();
                    String select = "SELECT item_description,item_mass," +
                            "item_cost" +
                            " FROM " + Constants.WEB_TABLE +
                            " WHERE key_year = '"+key_year+"'" +
                            " AND key_office = '"+key_office+ "'"+
                            " AND key_client = '"+key_client+ "'"+
                            " AND key_company = '"+key_company+ "'"+
                            " AND key_item = " + itemNumber;
                    rst = stat.executeQuery(select);
                    while(rst.next()){
                        item = new LineItem();
                        item.setItem_description(rst.getString("item_description"));
                        item.setItem_mass(Float.parseFloat(rst.getString("item_mass")));
                        item.setKey_item(Integer.parseInt(rst.getString("item_cost")));
                        //////other details records ommited//////////////////////////
                        /* A HashMap of all itemTaxeCodes as its keys and an
                         * ArrayList of itemTaxedetails as its values
                        taxDetails = getItemTaxDetails(item.getKey_year(),item.getKey_office(),
                                item.getKey_client(),item.getKey_company(),item.getKey_item());
                        //item tax details
                        item.setItmTaxes(taxDetails);
                        //list of items with tax details
                        lineItems.add(item);
            } catch (SQLException ex) {
                ex.printStackTrace();
            } finally{
                SQLHelper.cleanUp(rst, stat, conn);
            return lineItems;
        public Set getOrders(String key_year,String key_office,
                String key_client,String key_company){
            List lineItems = new ArrayList();
            Set lineOrders = new HashSet();
            Connection conn = null;
            Statement stat = null;
            ResultSet rst = null;
            LineOder lineOrder = null;
            String select = "SELECT * FROM " + Constants.WEB_TABLE +
                    " WHERE key_year = '" + key_year + "'" +
                    " AND key_office = '" + key_office + "'" +
                    " AND key_client = '" + key_client + "'" +
                    " AND key_company = '" + key_company + "'";
            DbConnection dbConn = new DbConnection();
            try {
                conn = dbConn.getDbConnection(Constants.WEB_JNDI);
                stat = conn.createStatement();
                rst = stat.executeQuery(select);
                while(rst.next()){
                    lineOrder = new LineOder();
                    lineOrder.setKey_year(rst.getString("key_year"));
                    lineOrder.setKey_office(rst.getString("key_office"));
                    lineOrder.setKey_client(rst.getString("key_client"));
                    lineOrder.setKey_company(rst.getString("key_company"));
                    ////list of items with all their details
                    lineItems = getAllItemDetails(lineOrder.getKey_year(),lineOrder.getKey_office(),
                            lineOrder.getKey_client(),lineOrder.getKey_company());
                    //setting item details
                    lineOrder.setItems(lineItems);
                    //a list of order with all details
                    lineOrders.add(lineOrder);
            } catch (SQLException ex) {
                ex.printStackTrace();
            } finally{
                SQLHelper.cleanUp(rst, stat, conn);
            return lineOrders;
    Controller.java
    package orderitems;
    import java.io.*;
    import java.util.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class Controller extends HttpServlet {
        private Map taxDetails = new HashMap();
        private OrderDetails orderDetails = null;
        protected void processRequest(HttpServletRequest request,
                HttpServletResponse response)throws
                ServletException, IOException {
            response.setContentType("text/html;charset=UTF-8");
            String key_year = "2007";
            String key_office = "VZX00";
            String key_company = "DG20";
            String key_client =  "ZI001";
            int key_item = 1;
            String nextView = "/taxdetails_list.jsp";
            orderDetails = new OrderDetails();
            taxDetails = orderDetails.getItemTaxDetails(key_year,key_office,
                    key_company,key_client,key_item);
            //Store the collection objects into HTTP Request
            request.setAttribute("taxDetails", taxDetails);
            RequestDispatcher reqstDisp =
                    getServletContext().getRequestDispatcher(nextView);
            reqstDisp.forward(request,response);
        protected void doGet(HttpServletRequest request,
                HttpServletResponse response)throws
                ServletException, IOException {
            processRequest(request, response);
        protected void doPost(HttpServletRequest request,
                HttpServletResponse response)throws
                ServletException, IOException {
            processRequest(request, response);
    taxdetails_list.jsp
    <%@page contentType="text/html"%>
    <%@page pageEncoding="UTF-8"%>
    <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
        <head>
            <title>Simple Tax Detail Diaplay ::</title>
            <link rel="stylesheet" type="text/css" href="imgs/orders.css"/>
        </head>
        <body>
            <jsp:useBean id="taxDetails" class="java.util.HashMap" scope="request"/>
            <table>
                <c:forEach items="${taxDetails}" var="hMap">
                    <tr>
                        <td><c:out value="${hMap.key}" /></td>
                        <!--td><%--c:out value="${hMap.value}" /--%></td-->
                    </tr>
                </c:forEach>
            </table>
        </body>
    </html>am displaying taxCodes(in this case i have VAT and ICD) fine but cant figure out how to display a list of value for each taxCode.Here is the output am getting
    both in my JSP and on the console:
    *******************************CONSOLE OUTPUT****************************
    Key          Value
    ICD     [orderItems.ItemTax@13e6226, orderItems.ItemTax@9dca26]
    VAT [orderItems.ItemTax@13e6226, orderItems.ItemTax@9dca26]
    Edited by: aiEx on Oct 8, 2007 6:54 AM

    hi evnafets,
    yes i need a nested for loop.I have tried your advice but my bean properties are not found.Am getting this error:
    javax.servlet.ServletException: Unable to find a value for "key_item" in object of class "java.lang.String" using operator "."
    I have tried this as stated earlier in the post:I have tried to make the method getItemTaxDetails return a List and get the returned list value as taxDetails. I then tested to display this list on JSP and its displaying fine.
    public List getItemTaxDetails(String key_year,String key_office,
                String key_client,String key_company,int key_item){
            ItemTax taxDetail = null;
            List taxDetails = new ArrayList();
            List itemTaxCodes = new ArrayList();
            Map itemTaxDetails = new HashMap();
            Connection conn = null;
            Statement stat = null;
            ResultSet rst = null;
            //get a list of all tax codes of an item with a
            //given item number
            itemTaxCodes = getAllTaxCodes(key_item,key_year,
                    key_office,key_client,key_company);
            DbConnection dbConn = new DbConnection();
            try {
                conn = dbConn.getDbConnection(Constants.WEB_JNDI);
                stat = conn.createStatement();
                for(Iterator taxCodeIter= itemTaxCodes.iterator(); taxCodeIter.hasNext();){
                    ItemTax itemTaxCode = (ItemTax)taxCodeIter.next();
                    String taxCode = itemTaxCode.getKey_tax_code();
                    String select = "SELECT tax_type,tax_value," +
                            "tax_limit_val FROM "+ Constants.WEB_TABLE +
                            " WHERE key_item = "+ key_item +
                            " AND key_year = '" + key_year + "'" +
                            " AND key_office = '" + key_office + "'" +
                            " AND key_client = '" + key_client + "'" +
                            " AND key_company = '" + key_company +"'" +
                            " AND key_tax_code = '" + taxCode + "'";
                    rst = stat.executeQuery(select);
                    while(rst.next()){
                        taxDetail = new ItemTax();
                        //records to be displayed only
                        taxDetail.setKey_item(Integer.parseInt(rst.getString("key_item")));
                        taxDetail.setTax_value(rst.getString("tax_value"));
                        taxDetail.setTax_limit_val(Float.parseFloat(rst.getString("tax_limit_val")));
                        //////other details records ommited//////////////////////////
                        taxDetails.add(taxDetail);////An ArrayList of taxDetails for each taxCode
                     * A HashMap which has all taxCodes of an item as its keys
                     * and an ArrayList of taxdetails as its values.
                     * I return this for display in a JSP.
                    itemTaxDetails.put(taxCode,taxDetails);
            } catch (SQLException ex) {
                ex.printStackTrace();
            } finally{
                SQLHelper.cleanUp(rst, stat, conn);
            //return itemTaxDetails;
            return taxDetails;
        }And my JSP
    taxdetails_list.jsp
    <%@page contentType="text/html"%>
    <%@page pageEncoding="UTF-8"%>
    <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <link rel="stylesheet" type="text/css" href="imgs/orders.css"/>
        </head>
        <body>
            <table>
                <c:forEach var="curRecord" items="${taxDetails}" varStatus="rowCounter">
                        <c:choose>
                            <c:when test="${rowCounter.count % 2 == 0}">
                                <c:set var="rowStyle" scope="page" value="odd" />
                            </c:when>
                            <c:otherwise>
                                <c:set var="rowStyle" scope="page" value="even" />
                            </c:otherwise>
                        </c:choose>
                        <tr class="${rowStyle}">
                            <td>${curRecord.key_item}</td>
                            <td>${curRecord.tax_value}</td>
                            <td>${curRecord.tax_limit_val}</td>
                        </tr>
                    </c:forEach>
            </table>
        </body>
    </html>I can't see where am going wrong even with your advice.Please help.
    Thnx.

  • How to use Multimaps (Map String, ArrayList String )

    I was using an array to store player names, userIDs, uniqueIDs, and frag counts, but after reading about multimaps in the tutorials, it seems that would be much more efficient. However, I guess I don't quite understand it. Here's how I wanted things stored in my string array:
    String[] connectedUsers = {"user1_name", "user1_userid", "user1_uniqueid", "user1_frags"
                                            "user2_name"...}and here is how I'm attempting to setup and use the 'multimap':
    public class Main {
        static Map<String, ArrayList<String>> connectedUsers;
        public void updatePlayers(String name, String status) {
            String[] statusSplit = status.split(" ");
            if (connectedUsers.containsKey(name)) {
                connectedUsers.put(name, statusSplit[0]);
            else {
                connectedUsers.put(name, statusSplit[0]);
        }It's quite obvious I don't understand how this works, but should I even set this multimap up this way? Perhaps I should use a regular map with a string array for the values?

    You're cool MrOldie. Its just that alarm bells start ringing in my head when people come on and post as much as you do.
    * Created on Jul 28, 2005 by @author Tom Jacobs
    package tjacobs;
    import java.util.ArrayList;
    import java.util.Collection;
    import java.util.HashMap;
    import java.util.Iterator;
    import java.util.LinkedList;
    import java.util.Map;
    import java.util.Set;
    import java.util.TreeSet;
    * ManyMap is a map that allows more than one value to be stored with any key
    * <p>
    * There are a number of methods in the class that have been deprecated because
    * the original functionality of Map has been violated to accomodate the concept
    * of the ManyMap
    public class ManyMap<T, T2> implements Map<T, T2> {
         private HashMap<T, ArrayList<T2>> mInnerMap;
         public ManyMap() {
              mInnerMap = new HashMap<T, ArrayList<T2>>();
          * @deprecated
         public T2 get(Object obj) {
              ArrayList<T2> ar = _get(obj);
              if (ar == null || ar.size() == 0) {
                   return null;
              return ar.get(0);
         public Iterator<T2> getAll(Object obj) {
              ArrayList<T2> ar = _get(obj);
              if (ar == null || ar.size() == 0) {
                   return null;
              return ar.iterator();          
         public T2 put(T obj1, T2 obj2) {
              ArrayList<T2> ar = _getNotNull(obj1);
              ar.add(obj2);
              return obj2;
         public Set<Map.Entry<T, T2>> entrySet() {
              TreeSet<Map.Entry<T, T2>> entries = new TreeSet<Map.Entry<T, T2>>();
              Iterator<T> _i = mInnerMap.keySet().iterator();
              while (_i.hasNext()) {
                   T key = _i.next();
                   Iterator<T2> vals = mInnerMap.get(key).iterator();
                   while (vals.hasNext()) {
                        Entry<T, T2> entry = new Entry<T, T2>(key, vals.next());
                        entries.add(entry);
              return entries;
         public int size() {
              return mInnerMap.size();
         public int valuesSize() {
              int vals = 0;
              Iterator<T> _i = mInnerMap.keySet().iterator();
              while (_i.hasNext()) {
                   T key = _i.next();
                   ArrayList<T2> ar = mInnerMap.get(key);
                   vals += ar.size();
              return vals;
         public void clear() {
              mInnerMap.clear();
         public void putAll(Map<? extends T, ? extends T2> map) {
              Iterator _i = map.entrySet().iterator();
              while(_i.hasNext()) {
                   Map.Entry<? extends T, ? extends T2> entry = (Map.Entry<? extends T, ? extends T2>) _i.next();
                   put(entry.getKey(), entry.getValue());
         public Collection <T2> values() {
              LinkedList ll = new LinkedList();
              Iterator<ArrayList<T2>> _i = mInnerMap.values().iterator();
              while (_i.hasNext()) {
                   ll.addAll(_i.next());
              return ll;
         public boolean containsValue(Object val) {
              Iterator<ArrayList<T2>> values = mInnerMap.values().iterator();
              while (values.hasNext()) {
                   if (values.next().contains(val)) return true;
              return false;
         public boolean containsKey(Object key) {
              return mInnerMap.containsKey(key);
         public T2 remove(Object obj) {
              Iterator<ArrayList<T2>> values = mInnerMap.values().iterator();
              boolean found = false;
              while (values.hasNext()) {
                   if (values.next().remove(obj)) {
                        found = true;
              return found ? (T2)obj : null;
         public boolean isEmpty() {
              return valuesSize() == 0;
         @SuppressWarnings("hiding")
         private class Entry<T, T2> implements Map.Entry<T, T2> {
              T key;
              T2 val;
              public Entry (T obj1, T2 obj2) {
                   key = obj1;
                   val = obj2;
              public T2 getValue() {
                   return val;
              public T getKey() {
                   return key;
              public T2 setValue(T2 obj) {
                   return val = obj;
         public Set<T> keySet() {
              return mInnerMap.keySet();
         public ArrayList<T2> _get (Object obj) {
              return mInnerMap.get(obj);
         public ArrayList<T2> _getNotNull (T obj) {
              ArrayList<T2> list = _get(obj);
              if (list == null) {
                   list = new ArrayList<T2>(1);
                   mInnerMap.put(obj, list);
              return list;
    }Edited by: tjacobs01 on Aug 19, 2008 12:28 PM

  • Get key values from HashMap

    Hi,
    I'm trying to get the values of the keys in my HashMap into a String array. Here is the code I'm using:
    HashMap row = new HashMap();
    row.put("A","Approved");
    row.put("D","Disapproved");
    row.put("P","Pending Approval");
    row.put("S","For Simulation Only");
    String[] key = new String[row.size()];
    int k=0;
    while (row.keySet().iterator().hasNext()) {
         key[k] = (String)row.keySet().iterator().next();
         k++;
    }What I'm getting:
    key[0] = "A"
    key[1] = "A"
    key[2] = "A"
    key[3] = "A"
    What I want is:
    key[0] = "A"
    key[1] = "D"
    key[2] = "P"
    key[3] = "S"
    Help, please!

    kd, I know that feeling...
    String[] keys = (String[]) row.keySet().toArray(new String[0]);
    In this case toArray will realize that the zero-length array
    is too short and create/return a new array containing objects
    of type String.Strictly speaking, if you don't give any array (toArray()), the array is an Object[], and as kd said, you can't cast to some other type.
    If you give an array of a specific type, you can cast. If that array is too small, the method will create a new array of the correct type. So you might as well pass it an array at least as big, since in this case you can tell how big it should be. This avoids allocating 2 arrays. Obviously the other will is likely to be GC'd, but why create it if not needed. Maybe that's too much of a micro optimization.

  • Webdynpro " How to add values in Drop down list By Key"

    Hi experts ,
    i want to create a drop down list by key, i don't know how to assign values to it ( i.e. add list entries ) . Please help me on this ..
    With regards ,
    James..
    Valuable answers will be rewarded ....

    Hi,
    To fix values to the drop down key at runtime in the webdynpro application you can use the following code:
    DATA:
    lr_node_flightinfo TYPE REF TO if_wd_context_node,
    lr_nodeinfo_flightinfo TYPE REF TO if_wd_context_node_info,
    l_scarr type scarr,
    lt_value_set TYPE TABLE OF wdr_context_attr_value,
    lw_value_set like line of lt_value_set.
    get nodeinfo of node flightinfo
    lr_node_flightinfo = wd_context->get_child_node( name = 'FLIGHTINFO' ).
    lr_nodeinfo_flightinfo = lr_node_flightinfo->get_node_info( ).
    get value set (VALUE = CARRID , TEXT = CARRNAME)
    select carrid carrname from scarr into table lt_value_set.
    clear lw_value_set.
    lw_value_set-value = 'AI'.
    lw_value_set-text = 'Air India'.
    append lw_value_set to lt_value_set.
    sort the value set by the describing TEXT
    SORT lt_value_set BY text.
    set value to context attribute
    lr_nodeinfo_flightinfo->set_attribute_value_set(
    name = 'CARRID' value_set = lt_value_set ).
    Here CARRID is a drop down by key field on the screen.
    in The context it is an attribute in the node FLIGHTINFO.
    Please give Reward Points if this piece of code helps
    Regards,
    Manish

  • How to make use of a list partition key in an IR?

    Hi all -- wondering if anyone has any thoughts on the following:
    I have a table like this:
    CREATE TABLE protocol (
    ptl_id INTEGER,
    ptl_name VARCHAR2(100),
    and this table is LIST partitioned on the key value PTL_ID. (There are many reasons for this need which I won't go into).
    My question is, queries that use this table in Interactive Reports I have always have the PTL_ID in them, but it's never a displayed column, it's always hidden (as it's a meaningless surrogate key, not to display to the user). However the default IR behavior, when filtering, won't use it, it will use PTL_NAME (if filtering on a particular PROTOCOL).
    What can I do to make the IR use the list partition key PTL_ID instead of PTL_NAME, even though PTL_ID is hidden and PTL_NAME is displayed? I'd get MUCH better performance if I could get it to query via the list partition key.
    Any thoughts??
    Thanks!
    David

    Users can change the name of the protocol at will, so that is not an option. Switching the partitioning is not an option either, as the PTL_ID's/partitions get pre-created during scheduled maintenance, and there is no tolerance to downtime to create a new partition for every new protocol as they are needed.
    Each partition is put in a separate tablespace as there is a need to archive off protocols once they are done.
    So I'm back to the original question still. My guess is the answer involves a bunch coding work arounds, not something native in the IRs. I figured I'd ask.
    Thanks
    David

  • Convert from String to HashMap

    Hi
    Can any body pls tell us how to convert from String to HashMap
    I have one string str="Col1=200, Col2=225";
    So how can i convert that string varibale into HashMap?

    Hi
    Can any body pls tell us how to convert from String
    to HashMap
    I have one string str="Col1=200, Col2=225";
    So how can i convert that string varibale into
    HashMap?
    Map map = new HashMap();
    String[] parts = str.split(", ");
    for (int i = 0; i < parts.length; ++i) {
        String[] entry = parts.split("=");
    map.put(entry[0], entry[1]);

  • [svn] 3246: Fix fasttrack bug SDK-16910 - Simple List populated with strings throws RTE .

    Revision: 3246
    Author: [email protected]
    Date: 2008-09-17 15:31:25 -0700 (Wed, 17 Sep 2008)
    Log Message:
    Fix fasttrack bug SDK-16910 - Simple List populated with strings throws RTE. This is fallout from the Group/DataGroup split. DefaultItemRenderer now uses a TextBox instead of a Group to show the list data.
    QE: Any List tests that depended on the default item renderer to support anything other than text must be updated.
    Bugs: SDK-16910
    Ticket Links:
    http://bugs.adobe.com/jira/browse/SDK-16910
    http://bugs.adobe.com/jira/browse/SDK-16910
    Modified Paths:
    flex/sdk/trunk/frameworks/projects/flex4/src/flex/skin/DefaultItemRenderer.mxml

    BTW, I do not experience the bug you had mentioned at
    http://www.cs.rit.edu/~cxb0025/flex/TreeControlBugs.html
    Can submit a video of my actions recorded

  • [Solved] gpg --list-public-keys (removed duplicate - see my last post)

    I followed https://wiki.archlinux.org/index.php/GnuPG#Create_key and https://wiki.archlinux.org/index.php/Talk:Pacman-key, but I have ended up with my public key being listed twice. It's both first and last in the full list of public keys. Here is just mine:
    /home/colin% gpg --list-public-keys colin
    pub   4096R/0940E3F9 2014-11-18 [expires: 2015-11-18]
    uid       [ultimate] Colin Keenan <[email protected]>
    uid       [ultimate] [jpeg image of size 6283]
    sub   4096R/EDA19F9C 2014-11-18 [expires: 2015-11-18]
    pub   4096R/0940E3F9 2014-11-18 [expires: 2015-11-18]
    uid       [ultimate] Colin Keenan <[email protected]>
    uid       [ultimate] [jpeg image of size 6283]
    sub   4096R/EDA19F9C 2014-11-18 [expires: 2015-11-18]
    How do I remove just the 2nd entry so that my public key is only listed one time?
    I am afraid to start signing my packages (https://wiki.archlinux.org/index.php/De … ge_signing) before I fix this issue.
    Edit to add what I've tried so far:
    gpg -o colin.gpg --export colin            # to create a backup of my public key in a file called colin.gpg
    cp pubring.gpg pubring-backup.gpg   # in case I screw up pubring.gpg
    gpg --import colin.gpg                          # hoping it will magically merge the duplicate, but it left both unchanged
    gpg --delete-key colin                           # hoping it would delete both copies of the public key so I could import it again
    It refused to delete the public key until I delete the private key which I don't want to do.
    I also realized the export may have the duplicate as well. I tested that with:
    gpg colin.gpg
    And, sure enough, it listed my key twice.
    Another edit: I have tried a lot and exposed a bug that I will try to submit upstream. Here is what I have done:
    gpg --edit-key colin                              # this selected the first of the duplicate keys to be edited
    gpg> adduid
    Real name: Colin N Keenan
    Email address: [email protected]
    Comment:
    You selected this USER-ID:
        "Colin N Keenan <[email protected]>"
    Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? O
    You need a passphrase to unlock the secret key for
    user: "Colin Keenan <[email protected]>"
    4096-bit RSA key, ID 0940E3F9, created 2014-11-18
    pub  4096R/0940E3F9  created: 2014-11-18  expires: 2015-11-18  usage: SC 
                         trust: ultimate      validity: ultimate
    sub  4096R/EDA19F9C  created: 2014-11-18  expires: 2015-11-18  usage: E   
    [ultimate] (1)  Colin Keenan <[email protected]>
    [ultimate] (2)  [jpeg image of size 6283]
    [ unknown] (3). Colin N Keenan <[email protected]>
    gpg> save
    gpg --edit-key "Colin N Keenan"
    Secret key is available.
    pub  4096R/0940E3F9  created: 2014-11-18  expires: 2015-11-18  usage: SC 
                         trust: ultimate      validity: ultimate
    sub  4096R/EDA19F9C  created: 2014-11-18  expires: 2015-11-18  usage: E   
    [ultimate] (1). Colin N Keenan <[email protected]>
    [ultimate] (2)  Colin Keenan <[email protected]>
    [ultimate] (3)  [jpeg image of size 6283]
    gpg> 2
    pub  4096R/0940E3F9  created: 2014-11-18  expires: 2015-11-18  usage: SC 
                         trust: ultimate      validity: ultimate
    sub  4096R/EDA19F9C  created: 2014-11-18  expires: 2015-11-18  usage: E   
    [ultimate] (1). Colin N Keenan <[email protected]>
    [ultimate] (2)* Colin Keenan <[email protected]>
    [ultimate] (3)  [jpeg image of size 6283]
    gpg> deluid
    Really remove this user ID? (y/N) y
    pub  4096R/0940E3F9  created: 2014-11-18  expires: 2015-11-18  usage: SC 
                         trust: ultimate      validity: ultimate
    sub  4096R/EDA19F9C  created: 2014-11-18  expires: 2015-11-18  usage: E   
    [ultimate] (1). Colin N Keenan <[email protected]>
    [ultimate] (2)  [jpeg image of size 6283]
    gpg> quit
    Save changes? (y/N) y
    And now the bug:
    /home/colin% gpg --delete-key "Colin Keenan"
    gpg (GnuPG) 2.0.26; Copyright (C) 2013 Free Software Foundation, Inc.
    This is free software: you are free to change and redistribute it.
    There is NO WARRANTY, to the extent permitted by law.
    gpg: there is a secret key for public key "Colin Keenan"!
    gpg: use option "--delete-secret-keys" to delete it first.
    /home/colin% gpg --delete-secret-key "Colin Keenan"
    gpg (GnuPG) 2.0.26; Copyright (C) 2013 Free Software Foundation, Inc.
    This is free software: you are free to change and redistribute it.
    There is NO WARRANTY, to the extent permitted by law.
    gpg: key "Colin Keenan" not found: Unknown system error
    gpg: Colin Keenan: delete key failed: Unknown system error
    So, --delete-key fails because there is a secret key, and --delete-secret-key fails because it can't find the secret key!
    Last edited by colinkeenan (2014-11-19 16:26:31)

    I have solved the issue. Since I had made a backup of .gnupg while there was a duplicate of the public key for "Colin Keenan", I realized the secret key in the backup was also for "Colin Keenan", so I didn't want to delete that one. I should delete "Colin N Keenan" by deleting the secret and public key matching it, then copy the resulting public key file to the backup, then restore the backup. That solved the issue, as follows:
    gpg --delete-secret-key "Colin N Keenan"
    gpg --delete-key "Colin N Keenan"
    cp .gnupg/pubring.gpg .gnupg-backup
    rm -r .gnupg
    cp -r .gnupg-backup .gnupg
    Here is a full outline of the commands I ran to eliminate the duplicate public key, in case anyone else runs into this very unusual problem:
    cd                                     # just making sure I'm in home directory so don't have to type dreaded ~
    cp -r .gnupg .gnupg-backup
    gpg --edit-key colin
    gpg> adduid (added Colin N Keenan, original was Colin Keenan)
    gpg> save
    gpg --edit-key "Colin N Keenan"
    gpg> 2 (because "Colin Keenan" was the 2nd uid)
    gpg> deluid
    gpg> save
    gpg --delete-secret-key "Colin N Keenan"
    gpg --delete-key "Colin N Keenan"
    cp .gnupg/pubring.gpg .gnupg-backup
    rm -r .gnupg
    cp -r .gnupg-backup .gnupg
    Last edited by colinkeenan (2014-11-19 16:41:03)

  • How can we scan the Key Strings of any UI

    please tell me the way so that i can scan all the key strings of any UI.

    Are u trying to write a Spy program. :)

  • Where is list of keys and what they do?

    Where can I find a list of keys and what they do. I'm a command line kind of guy.
    Using Mac mini / Panther
    larryalk

    364/2810
    Hi larryalk,
    welcome to Discussions!
    In addition to Kurt's excellent link,
    Here are the ones you can print "just in case":
    - Shortcuts for freezes
    This one has all useful links:
    - Mac OS X keyboard shortcuts
    This one is very handy:
    - Mac OS: Apple Pro Keyboard Shortcuts for Shut Down and Restart
    Also:
    Many keyboard shortcuts are not documented. Just try holding the Option key in combination with the usual ones, see what it does. Same with the Control key and the Shift key.
    In popping dialog boxes:
    Usually command+dot = Cancel, and
    hitting the initial letter often equals a mouse-click.
    In the menubar and the menus:
    Also simply hitting a letter.
    Or two letters if needed, like HI = History when H(E) = Help.
    ⇧ Shift
    ⌥ Option
    ⌘ Command
    ⌃ Control
    Have fun!
    Axl
    Happy New Year Kurt!

  • Read Key(String).vi and spaces

    Hello all,
    I am having some trouble with the Read Key(String).vi. One of the strings I am reading in ends in spaces. This vi seems to want to truncate any trailing spaces. I don't want it to do that. Is there anyway of modifing the vi to not truncate spaces? Or should I not allow spaces to be written?
    Thanks in advance,
    Glen

    I haven't dug very far into the config file VIs but the easiest thing to do is to enclose all of your strings with quote marks ("). If you do that, key values with trailing spaces are read correctly.

Maybe you are looking for

  • Excise Group and Excise Register issue

    Hi Friends, We have internal order budgeting for consumables.whenever we make purchase order , the account assignment category is F and we purcahse against the particular internal order.when G/R is done the consumable material gets cosnumed against t

  • DB Partition on windows environment

    Dear Expert, I am trying to add a database partition server on our BI server using db2ncrt command. The logical partition was created on the same db instance (one machine). The issue appears when running the following command: E:\Program Files\IBM\SQ

  • Flash Wont Display and other bugs

    As far as the flash thing is concerned i am going to try installing flash 7/8 as i believe that flash 9 does'nt work with the latest safari. However i also have another problem, on the same page that the flash objects don't display there are small di

  • Encoding error on iBooks

    I recently upgrade to the latest iphone operating system for the iPhone 4 and now get an encoding error on all the books I've purchased. Is there a way to fix the error? Thanks

  • ISight on MacPro used by MacBook Pro?

    Anyone knows if it would be possible for a MacBook Pro to access the iSight camera on a MacPro via a wireless network and what software you would use on the MacBook Pro to access the camera? It would just be the coolest way ever to check on the baby