Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to Convert an ArrayList into Collection

Posted on 2004-09-02
9
Medium Priority
?
644 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
  • +1
9 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 1400 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 400 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 200 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
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 video teaches viewers about errors in exception handling.
Suggested Courses

636 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