Solved

How to Convert an ArrayList into Collection

Posted on 2004-09-02
9
630 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
 
LVL 92

Expert Comment

by:objects
ID: 11968890
what error are you getting, and can you post your tag
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
The viewer will learn how to implement Singleton Design Pattern in Java.

758 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

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now