Example usage for java.util Iterator hasNext

List of usage examples for java.util Iterator hasNext

Introduction

In this page you can find the example usage for java.util Iterator hasNext.

Prototype

boolean hasNext();

Source Link

Document

Returns true if the iteration has more elements.

Usage

From source file:Main.java

public static void main(String[] args) {
    List<Integer> _numbers = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
    Iterator<Integer> iter = _numbers.stream().filter(value -> value % 2 == 0).iterator();

    while (iter.hasNext()) {
        System.out.println(iter.next());
    }//from   ww  w.j  a va  2 s  .  c  o  m
}

From source file:Main.java

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

    SOAPConnectionFactory sfc = SOAPConnectionFactory.newInstance();
    SOAPConnection connection = sfc.createConnection();

    MessageFactory mf = MessageFactory.newInstance();
    SOAPMessage sm = mf.createMessage();
    QName bodyName = new QName("http://YourSOAPServer.com", "GetQuote", "d");
    URL endpoint = new URL("http://YourSOAPServer.com");
    SOAPMessage response = connection.call(sm, endpoint);

    SOAPBody sb = response.getSOAPBody();
    java.util.Iterator iterator = sb.getChildElements(bodyName);
    while (iterator.hasNext()) {
        SOAPBodyElement bodyElement = (SOAPBodyElement) iterator.next();
        String val = bodyElement.getValue();
        System.out.println("The Value is:" + val);
    }/*  w w w  . j a  v a  2s  .co m*/
}

From source file:Main.java

public static void main(String[] args) {
    ArrayList aList = new ArrayList();
    aList.add("1");
    aList.add("2");
    aList.add("3");
    aList.add("4");
    aList.add("java2 s .com");
    System.out.println("ArrayList: ");
    System.out.println(aList);/*from  w  w w . ja v a2 s . c  om*/
    Iterator itr = aList.iterator();
    String strElement = "";
    while (itr.hasNext()) {
        strElement = (String) itr.next();
        if (strElement.equals("2")) {
            itr.remove();
            break;
        }
    }
    System.out.println("ArrayList after removal : ");
    System.out.println(aList);
}

From source file:MainClass.java

public static void main(String args[]) {
    ArrayList<String> al = new ArrayList<String>();

    al.add("C");/*from   ww w  . ja  va  2 s .  c o  m*/
    al.add("A");
    al.add("E");
    al.add("B");
    al.add("D");
    al.add("F");

    System.out.print("Original contents of al: ");
    Iterator<String> itr = al.iterator();
    while (itr.hasNext()) {
        String element = itr.next();
        System.out.print(element + " ");
    }
    System.out.println();

    ListIterator<String> litr = al.listIterator();
    while (litr.hasNext()) {
        String element = litr.next();
        litr.set(element + "+");
    }

    // Now, display the list backwards.
    System.out.print("Modified list backwards: ");
    while (litr.hasPrevious()) {
        String element = litr.previous();
        System.out.print(element + " ");
    }
}

From source file:Main.java

public static void main(String[] args) {
    HashMap<String, Integer> map = new HashMap<String, Integer>();
    map.put("d", 5);
    map.put("c", 4);
    map.put("b", 2);
    map.put("a", 1);

    Integer value[] = new Integer[map.size()];

    Set keySet = map.keySet();/*from  www . j  a v  a  2  s. c  o m*/
    Iterator t = keySet.iterator();
    int a = 0;
    while (t.hasNext()) {
        value[a] = map.get(t.next());
        a++;
    }

    Arrays.sort(value);

    for (int i = 0; i < map.size(); i++) {
        t = keySet.iterator();
        while (t.hasNext()) {
            String temp = (String) t.next();
            if (value[i].equals(map.get(temp))) {
                System.out.println(value[i] + " = " + temp);
            }
        }
    }
}

From source file:com.discursive.jccook.bean.BeanUtilExample.java

public static void main(String[] pArgs) {

    if (pArgs.length > 0 && pArgs[0] != null) {
        propName = pArgs[0];/*from   w w w  .ja  v a2  s  .c o  m*/
    }
    System.out.println("Getting Property: " + propName);

    List books = createBooks();

    Iterator i = books.iterator();
    while (i.hasNext()) {
        Book book = (Book) i.next();
        Object propVal = null;
        try {
            propVal = PropertyUtils.getProperty(book, propName);
        } catch (Exception e) {
            System.out.println("Error getting property: " + propName + ", from book: " + book.getName()
                    + ", exception: " + e.getMessage());
        }
        System.out.println("Property Value: " + propVal);
    }
}

From source file:MainClass.java

public static void main(String[] pArgs) throws Exception {
    Date now = new Date();
    System.out.println("now: " + DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.format(now));
    Iterator iter = DateUtils.iterator(now, DateUtils.RANGE_WEEK_SUNDAY);
    while (iter.hasNext()) {
        Calendar cal = (Calendar) iter.next();
        Date cur = cal.getTime();
        System.out.println("iterate: " + DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.format(cur));
    }/* ww w . jav  a2  s.c  om*/
}

From source file:Person.java

public static void main(String args[]) {
    ArrayList<Person> names = new ArrayList<Person>();
    names.add(new Person("E", "T"));
    names.add(new Person("A", "G"));
    names.add(new Person("B", "H"));
    names.add(new Person("C", "J"));

    Iterator iter1 = names.iterator();
    while (iter1.hasNext()) {
        System.out.println(iter1.next());
    }/*from   w w  w . j a  v  a 2s.  co m*/
    Collections.sort(names, new PersonComparator());
    Iterator iter2 = names.iterator();
    while (iter2.hasNext()) {
        System.out.println(iter2.next());
    }
}

From source file:Person.java

public static void main(String args[]) {
    ArrayList<Person> names = new ArrayList<Person>();
    names.add(new Person("E", "T"));
    names.add(new Person("A", "G"));
    names.add(new Person("B", "H"));
    names.add(new Person("C", "J"));

    Iterator iter1 = names.iterator();
    while (iter1.hasNext()) {
        System.out.println(iter1.next());
    }//from  ww  w. ja v  a  2 s.  c o m
    System.out.println("Before sorting");
    Collections.sort(names, new PersonComparator());
    Iterator iter2 = names.iterator();
    while (iter2.hasNext()) {
        System.out.println(iter2.next());
    }
}

From source file:SOAPResponse.java

public static void main(String[] args) {
    try {//  ww w .ja  v a 2  s. c o m
        SOAPConnectionFactory sfc = SOAPConnectionFactory.newInstance();
        SOAPConnection connection = sfc.createConnection();

        MessageFactory mf = MessageFactory.newInstance();
        SOAPMessage sm = mf.createMessage();
        QName bodyName = new QName("http://YourSOAPServer.com", "GetQuote", "d");
        URL endpoint = new URL("http://YourSOAPServer.com");
        SOAPMessage response = connection.call(sm, endpoint);

        SOAPBody sb = response.getSOAPBody();
        java.util.Iterator iterator = sb.getChildElements(bodyName);
        while (iterator.hasNext()) {
            SOAPBodyElement bodyElement = (SOAPBodyElement) iterator.next();
            String val = bodyElement.getValue();
            System.out.println("The Value is:" + val);
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}