?
Solved

How to Convert an ArrayList into Collection

Posted on 2004-09-02
9
Medium Priority
?
643 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

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 make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
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…
Suggested Courses
Course of the Month15 days, 8 hours left to enroll

741 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