Example usage for java.util Set iterator

List of usage examples for java.util Set iterator

Introduction

In this page you can find the example usage for java.util Set iterator.

Prototype

Iterator<E> iterator();

Source Link

Document

Returns an iterator over the elements in this set.

Usage

From source file:Main.java

public static void main(String[] args) {
    String text = "A,B,C,D";

    String[] keyValue = text.split(",");

    Map<Integer, String> myMap = new HashMap<Integer, String>();
    for (int i = 0; i < keyValue.length; i++) {
        myMap.put(i, keyValue[i]);/*from w w w  .  ja  v  a 2s . c om*/
    }

    Set keys = myMap.keySet();
    Iterator itr = keys.iterator();

    while (itr.hasNext()) {
        Integer key = (Integer) itr.next();
        String value = (String) myMap.get(key);
        System.out.println(key + " - " + value);
    }
}

From source file:MainClass.java

public static void main(String args[]) throws Exception {

    String elements[] = { "A", "C", "D", "G", "F" };
    Set set = new TreeSet(Arrays.asList(elements));
    Iterator iter = set.iterator();
    while (iter.hasNext()) {
        System.out.println(iter.next());
    }/*from  w  w  w .  j av a  2 s  .c  om*/
}

From source file:Main.java

public static void main(String[] args) throws IOException {
    String fileContent = "s1=1\n" + "s2=Main\n" + "s3=Fri Jan 31 00:00:00 IST 3913";
    StringReader reader = new StringReader(fileContent);

    PropertyResourceBundle bundle = new Main(reader);

    Set keySet = bundle.handleKeySet();
    Iterator keys = keySet.iterator();
    while (keys.hasNext()) {
        System.out.println("Bundle key: " + keys.next());
    }/*w ww  . ja  va 2 s. com*/

}

From source file:Main.java

public static void main(String[] args) throws IOException {
    String fileContent = "s1=1\n" + "s2=Main\n" + "s3=Fri Jan 31 00:00:00 IST 3913";
    InputStream propStream = new StringBufferInputStream(fileContent);

    PropertyResourceBundle bundle = new Main(propStream);

    // Get resource key set
    Set keySet = bundle.handleKeySet();
    Iterator keys = keySet.iterator();
    while (keys.hasNext()) {
        System.out.println("Bundle key: " + keys.next());
    }/*w  ww .  j av a2  s. c o  m*/

}

From source file:MainClass.java

public static void main(String[] a) {
    String elements[] = { "A", "B", "C", "D", "E" };
    Set set = new HashSet(Arrays.asList(elements));

    Iterator iter = set.iterator();
    while (iter.hasNext()) {
        System.out.println(iter.next());
    }/*  w w  w.java2s  . co m*/

}

From source file:Main.java

public static void main(String[] args) {
    Hashtable<String, String> ht = new Hashtable<String, String>();

    ht.put("1", "One");
    ht.put("2", "Two");
    ht.put("3", "Three");

    Set st = ht.keySet();

    Iterator itr = st.iterator();

    while (itr.hasNext()) {
        System.out.println(itr.next());
    }/*w w  w.  j av a 2s. c  om*/
    st.remove("2");

    Enumeration e = ht.keys();
    while (e.hasMoreElements()) {
        System.out.println(e.nextElement());
    }
}

From source file:Main.java

public static void main(String[] args) {
    LinkedHashMap<String, String> lHashMap = new LinkedHashMap<String, String>();

    lHashMap.put("1", "One");
    lHashMap.put("2", "Two");
    lHashMap.put("3", "Three");

    Set st = lHashMap.keySet();

    Iterator itr = st.iterator();

    while (itr.hasNext()) {
        System.out.println(itr.next());
    }/*  w  w w.j a  v a2  s.c o  m*/
    st.remove("2");

    boolean blnExists = lHashMap.containsKey("2");
    System.out.println(blnExists);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    // Prepare content for simulating property files
    String fileContent = "s1=1\n" + "s2=Main\n" + "s3=Fri Jan 31 00:00:00 IST 3913";
    InputStream propStream = new StringBufferInputStream(fileContent);

    // Create property resource bundle
    PropertyResourceBundle bundle = new Main(propStream);

    // Get resource key set
    Set keySet = bundle.handleKeySet();
    Iterator keys = keySet.iterator();
    while (keys.hasNext()) {
        System.out.println("Bundle key: " + keys.next());
    }/*from  w w w  .ja va  2s  .com*/

}

From source file:Main.java

public static void main(String[] args) {
    HashMap<String, Integer> myMap = new HashMap<String, Integer>();

    myMap.put("a", 1);
    myMap.put("b", 2);
    myMap.put("c", 3);

    Set<String> stStrKeys = myMap.keySet();
    Iterator<String> itrs = stStrKeys.iterator();
    while (itrs.hasNext()) {
        String s = itrs.next();//w w  w  . j  a  va 2  s . c  om
        System.out.println(s + ": " + myMap.get(s));
    }
}

From source file:MainClass.java

public static void main(String args[]) throws Exception {
    Hashtable hash = new Hashtable(89);
    hash.put("one", "two");
    hash.put("two", "three");
    hash.put("three", "four");
    hash.put("four", "five");
    System.out.println(hash);/* www . j  a  va  2 s. c  o  m*/
    System.out.println(hash.size());
    Enumeration e = hash.keys();
    while (e.hasMoreElements()) {
        String key = (String) e.nextElement();
        System.out.println(key + " : " + hash.get(key));
    }
    Set set = hash.entrySet();
    Iterator it = set.iterator();
    while (it.hasNext()) {
        Map.Entry entry = (Map.Entry) it.next();
        System.out.println(entry.getKey() + " : " + entry.getValue());
    }
}