Solved

How to Convert an ArrayList into Collection

Posted on 2004-09-02
9
636 Views
Last Modified: 2012-06-27
How can i convert an ArrayList to Collection?

With Struts, I have an ArrayList of members in my Action Class and i want it to convert to Collection so that i can use it in <html:optionsCollections>
0
Comment
Question by:ldbkutty
  • 4
  • 2
  • 2
  • +1
9 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 350 total points
ID: 11968351
An ArrayList *is* a Collection
0
 
LVL 32

Author Comment

by:ldbkutty
ID: 11968446
well, i dont have a chance to check with my Struts now, but when i tried ArrayList in <html:optionsCollections ...>, it didn't worked.

Probably, my mistake somewhere?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 11968475
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 92

Expert Comment

by:objects
ID: 11968890
what error are you getting, and can you post your tag
0
 
LVL 92

Assisted Solution

by:objects
objects earned 100 total points
ID: 11969677
the following should help you locate your problem:

http://www.webappbuilders.com/?content=html-optionscollection

Let me know if you have any questions.
0
 
LVL 3

Assisted Solution

by:vikraman_b
vikraman_b earned 50 total points
ID: 11970003
Hi ,
Just clear with the syntax.....
ArrayList itself a collection.... just check this..
yourjsp
--------
<html:select property="country" onChange="countryChange(createLoginAccForm)">
          <html:options  collection="countryList" property="value" labelProperty="label" />
        </html:select>

yourAction class
----------------
ArrayList arrayListL = (ArrayList) yourDAO.loadCountryList();


yourDAO class
-----------
public ArrayList loadCountryList() throws NamingException, SQLException {
            String countryCodeSQL = "select objid,country_cd ,country_name from country";

            ArrayList arrayList = new ArrayList();
            Connection conn = null;
            Statement stmt = null;
            ResultSet rs = null;

            String countryCode = null;
            String countryName = null;
            logger.debug("countryCodeSQL query:" + countryCodeSQL);

            try {
                  conn = DBUtils.getInstance().getConnection();
                  stmt = conn.createStatement();

                  stmt.execute(countryCodeSQL);
                  rs = stmt.getResultSet();

                  while (rs.next()) {
                        int objid = rs.getInt(1);
                        countryCode = rs.getString(2);
                        countryName = rs.getString(3);

                        arrayList.add(new KeyValueBean(objid, countryName));

                  }

            } catch (SQLException e) {
                  throw e;
            } finally {
                  try {
                        if (rs != null)
                              rs.close();
                  } catch (Exception e) {
                  }
                  try {
                        if (stmt != null)
                              stmt.close();
                  } catch (Exception e) {
                  }
                  try {
                        if (conn != null)
                              conn.close();
                  } catch (Exception e) {
                  }
            }
            return arrayList;
      }

Hope this will help
Regards
VIkraman
0
 
LVL 32

Author Comment

by:ldbkutty
ID: 11975569
thanks for all, but CEHJ gets the most. :-)
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 11975619
8-)
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 11975621
8-)
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
factorial example 4 47
sql import cannot be resolved jsp 3 45
Java Restore security prompts not working 10 56
What browser will run Java? 7 51
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question