2 Replies Latest reply on Jun 28, 2010 3:07 PM by 843793

    simple question

      hello there,,
                     ArrayList[][] al = new ArrayList[resultset.getRow()][3];
                          int count = 0;
                               List returnVar = new ArrayList();
                               returnVar.add(0, resultset.getInt("user_id"));
                               returnVar.add(1, resultset.getString("fullname"));
                               returnVar.add(2, resultset.getString("title"));
                               ht.put(count, returnVar);
      as you can see i initialized arraylist(al) and to be put() to Hashtable(ht)
      but when i return the Hashtable(ht) to the method caller and parses it
                Hashtable users = sd.getUsers(rowCount); // the method i shown above
                for(int i = 0; i < users.size(); i++)
                     Hashtable ht = new Hashtable();
                     List aaa = Arrays.asList(users.get(i));
                     for(int a = 0; a < aaa.size(); a++)
                          Object xyz = aaa.get(a);
                          System.out.println(aaa.get(a) + " " + a);
      it returns an object { value1, value2, value3 }
      my question is how can i parse these by index??

      aaa[0] = value1
      aaa[1] = value2
      aaa[2] = value3
        • 1. Re: simple question
          Why would you use a Hashtable when you want to access it by index?

          But if you really want to write bizarre code like that, you can always loop through numbers (since that's what your keys are) and just get them from the Hashtable normally.

          I'm amazed that you're writing SQL code there, yet you don't know how collections work.
          • 2. Re: simple question
            You might want to write like this
            List myList = new ArrayList();
            myList.add(new MyObject(resultset.getInt("user_id"), resultset.getInt("fullname"), resultset.getInt("title"));
            int myListSize = myList.size();
            int i;
            MyObject myObject;
            myObject = (MyObject) myList.get(i);