[SOLVED]Comparing elements in a collection to a variable?

Discussion in 'Plugin Development' started by civ77, Feb 10, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    civ77

    How would I compare the elements in a collection to a variable i.e. :

    int x;
    if(AnyElementInACollection < x)

    I don't care which elements are true or false I just need to know if any elements are true.
     
  2. Offline

    Zeerix

    Code:
    boolean anySmallerThan(Collection<Integer> list, int i) {
        for (int elem : list) {
            if (elem < i) {
                return true;
            }
        }
        return false;
    }
    
    untested.
     
    civ77 likes this.
  3. Offline

    civ77

    How could I modify this to work with a collection using strings as keys?
     
  4. Offline

    Zeerix

    change all occurances of "Integer" and "int" to "String". And think about what you would change "<" into.
     
  5. Offline

    civ77

    I am going to use your earlier suggestion and save the information that I was going to use as a Key in a seperate Arraylist. Thanks for the help.
     
Thread Status:
Not open for further replies.

Share This Page