How to find the index of an element in a TreeSet?

后端 未结 5 1243
执笔经年
执笔经年 2020-12-09 08:26

I\'m using a TreeSet and I\'d quite simply like to find the index of a number in the set. Is there a nice way to do this that actually makes use

5条回答
  •  再見小時候
    2020-12-09 08:53

    here show my function:

    //FUNCTION FOR GIVE A STRING POSITION INTO TREESET

    private static void get_posistion(TreeSet abre, String codig) {
        Iterator iterator;
        iterator = abre.iterator();
        int cont = 0;
        String prova = "";
    
        while (iterator.hasNext()) {                      
            prova = iterator.next().toString();
            if (codig.equals(prova)) {
                System.out.println(cont);
            } else {
                cont++;
            }
        }
    }
    

提交回复
热议问题