Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3405964
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T05:34:12+00:00 2026-05-18T05:34:12+00:00

hello friends in my project i have an arraylist showing results in a jsp

  • 0

hello friends in my project i have an arraylist showing results in a jsp page table of given contents of database, i want to add a filter to it to show only the matched contents from list,

the table which is coming out is as:
student_id class_id student_name
1x0001        10         Ashish
1x2001        11         Alex
1x2002        11         Atr.
1x0001        10         Alok

.............going on...

but i want the result to display page only for class_id::11 and remove other results how to do that?

List dataList = new ArrayList();
rs = s.getResultSet();
      while (rs.next ()){
        //Add records into data list
        dataList.add(rs.getInt("class_id"));
        dataList.add(rs.getString("name"));
        dataList.add(rs.getString("student_id"));
      }

and then showing result in servlet by getting arraylist:
what i want is to display the matter as a filtered table with arraylist not DB as:

the table which is coming(result???) out on servlet is as:
    student_id class_id student_name
    1x2001        11         Alex
    1x2002        11         Atr.

    .............going on...
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T05:34:12+00:00Added an answer on May 18, 2026 at 5:34 am

    You should filter at the SQL layer, like Adeel said.

    Also, you should use a Bean / Class / Struct to hold each record, rather than piling all data unstructured way into a single ArrayList.

    Nevertheless, the following code does what you ask:

    public class FilterTest {
        public static int COLS_PER_RECORD = 3;
    
        public static void main(String[] args) {
            ArrayList dataList = populateTestData();
            printRecords(dataList);
            ArrayList filtered = filterForClassId(dataList, 2);
            printRecords(filtered);
        }
    
        private static ArrayList populateTestData() {
            ArrayList dataList = new ArrayList();
            ResultSet rs = s.getResultSet();
            while (rs.next()) {
                dataList.add(rs.getInt("class_id"));
                dataList.add(rs.getString("name"));
                dataList.add(rs.getString("student_id"));
            }
            return dataList;
        }
    
        private static ArrayList filterForClassId(ArrayList dataList,
                int classIdToFilterFor) {
            ArrayList filtered = new ArrayList();
            Integer classIdToFilterForInteger = new Integer(classIdToFilterFor);
            for (int i = 0; i < dataList.size(); i += COLS_PER_RECORD) {
                if (classIdToFilterForInteger.equals(dataList.get(i))) {
                    for (int j = 0; j < COLS_PER_RECORD; j++) {
                        filtered.add(dataList.get(i + j));
                    }
                }
            }
            return filtered;
        }
    
        private static void printRecords(ArrayList dataList) {
            System.out.println("----");
            for (int i = 0; i < dataList.size(); i += COLS_PER_RECORD) {
                System.out.println("class_id=" + dataList.get(i) + " name="
                        + dataList.get(i + 1) + " student_id="
                        + dataList.get(i + 2));
            }
            System.out.println("----");
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello Friends check my code http://jsfiddle.net/sUaky/2/ i want to load a web page in
Hello friends i want to add more effects on my div when i click
Hello Friends I am using a list box control in aspx page i have
Hello friends I have three div tags on my page.. I am trying to
VS2005, ASP.NET, C#, IIS6 Hello friends, I have a master page divided into three
Hello I have a single friends table as follows: Id Sender Recipient Where sender
Hello friends I am having following table structure of quote Table I want to
Hello friends, I want to add a custom button on my searching string like
Hello friends I have tried many times but I am not successful than please
Hello friends i am running code given below which contains the setLogTimeEntery function and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.