Results 1 to 2 of 2
  1. #1
    Gunther34567 is offline Member
    Join Date
    May 2012
    Rep Power

    Default Counting objects in ArrayList


    I got a problem
    I want to show "statistics" of how many times a certain object is in my arraylist, gotten from my database, to send to my jsp page

    my code isn't the best but here it is

    Java Code:
                    //"keuzes" are the choices gotten from the database
                    //"keuzeAantal" is the arraylist with the amount of times the choices are in the arraylist
                    ArrayList<Keuze> keuzes = dakeuze.getKeuzes();
                    ArrayList<Keuze> keuzes2 = new ArrayList<>();
                    ArrayList<Integer> keuzeAantal = new ArrayList<>();
                    int i;
                    for(Keuze k : keuzes){
                        if (keuzes2.contains(k)){
                            i = keuzeAantal.get(keuzes.indexOf(k));
                        } else {
                    request.setAttribute("toonStatistieken", "ja");
                    request.setAttribute("keuzes", keuzes2);
                    request.setAttribute("keuzeAantal", keuzeAantal);
                    rd = request.getRequestDispatcher("admin.jsp");

    but the result on my jsp page is this (yes its in Dutch)

    Counting objects in ArrayList-java-probleem.png

    as you can see it puts every object in the arraylist with the amount 1
    but doesnt count it.

    am i overlooking something very simple and stupid, or is there an other solution?

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Washington, DC
    Rep Power

    Default Re: Counting objects in ArrayList

    If you want help, you'll have to provide an SSCCE that demonstrates the problem. We don't know what's in those lists, and we can't copy and paste that code to run it.

    But this seems like a job for a Map anyway.
    How to Ask Questions the Smart Way
    Static Void Games - GameDev tutorials, free Java and JavaScript hosting!
    Static Void Games forum - Come say hello!

Similar Threads

  1. Add objects to ArrayList with Polymorphism
    By africanhacker in forum New To Java
    Replies: 7
    Last Post: 06-29-2011, 02:59 PM
  2. ArrayList with Objects the right approach?
    By scheffetz in forum New To Java
    Replies: 1
    Last Post: 03-25-2011, 10:26 AM
  3. Help with objects in ArrayList
    By BiteMuncher in forum New To Java
    Replies: 7
    Last Post: 02-21-2011, 12:55 PM
  4. Counting vowles in a collection of String objects
    By sunde887 in forum New To Java
    Replies: 4
    Last Post: 01-18-2011, 08:22 AM
  5. ArrayList with different objects? Help
    By xtrmi in forum New To Java
    Replies: 4
    Last Post: 02-27-2009, 09:51 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts