4 Replies Latest reply: Mar 17, 2008 9:50 AM by 807601 RSS

    Help with an arraylist

    807601
      hey there guys
      i am having trouble with an arraylist.
      im wanting to pass a parameter into the arraylist but that will look at each indivdual person who has higher that number in a perticular variable.
      I havent a clue as to how to go about this

      Laura
        • 1. Re: Help with an arraylist
          807601
          are you saying you want to find all elements in the array that are higher than your number?

          than you must iterate through the array, and compare each element to your number.
          • 2. Re: Help with an arraylist
            807601
            i want to find the details of each of the objects in the arraylist but i want to find the people who are higher than the number that put in the parameter.
            I know i have to itterate through it but i dont know how to look at the variable. I know the rest of the code but not how to look at the variable i want to check
            • 3. Re: Help with an arraylist
              807601
              not sure what this means
              i want to find the people who are higher than the number that put in the parameter.
              to get the object from the arrayList, use get(int pos).
              then you have your object and can get anything else you want from it.

              if i'm not getting you, than please post code so i can understand your problem better.
              • 4. Re: Help with an arraylist
                807601
                ArrayList<String> alist = new ArrayList<String>();
                alist.add("one");
                alist.add("two");
                alist.add("three");
                
                for(String s : alist) {
                    if (s.equals("two")) {
                     System.out.println("I found two!");
                    }
                }
                
                //or
                
                for (int i = 0; i < alist.size(); i++) {
                    String s = alist.get(i);
                    if (s.equals("two")) {
                     System.out.println("I found two!");
                    }
                }