Solved

How to Convert an ArrayList into Collection

Posted on 2004-09-02
9
631 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

943 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

19 Experts available now in Live!

Get 1:1 Help Now