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:ArraySet.java

public static void main(String args[]) {
    String elements[] = { "A", "B", "C", "D", "E" };
    Set set = new ArraySet(Arrays.asList(elements));
    Iterator iter = set.iterator();
    while (iter.hasNext()) {
        System.out.println(iter.next());
    }/*from   w w  w  .  ja  v a  2s  . c o  m*/
}

From source file:ArraySet.java

public static void main(String args[]) {
    String elements[] = { "Java", "Source", "and", "Support", "." };
    Set set = new ArraySet(Arrays.asList(elements));
    Iterator iter = set.iterator();
    while (iter.hasNext()) {
        System.out.println(iter.next());
    }/*w w w . j  a  v a 2  s  . co m*/
}

From source file:de.netallied.functionblock.converter.java2java.util.Directory.java

public static void main(String[] params) {
    File temp = new File("C:\\Temp");
    ArrayList list = Directory.getAll(temp, true);
    Iterator it = list.iterator();
    while (it.hasNext()) {
        System.out.println(((File) (it.next())).getAbsolutePath());
    }// www  . j a  va2s . c  om
    System.out.println("Number of Files: " + list.size());
}

From source file:Main.java

public static void main(String[] args) {

    // create a LinkedList
    LinkedList<String> list = new LinkedList<String>();

    // add some elements
    list.add("Hello");
    list.add("from java2s.com");
    list.add("10");

    // print the list
    System.out.println("LinkedList:" + list);

    // set Iterator at specified index
    Iterator x = list.listIterator(1);

    // print list with the iterator
    while (x.hasNext()) {
        System.out.println(x.next());
    }//  w  ww .  j a v  a2s .c o  m
}

From source file:Main.java

public static void main(final String[] args) throws Exception {
    Random RND = new Random();
    ExecutorService es = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
    List<Future<String>> results = new ArrayList<>(10);
    for (int i = 0; i < 10; i++) {
        results.add(es.submit(new TimeSliceTask(RND.nextInt(10), TimeUnit.SECONDS)));
    }/*from  w  w  w.ja  v  a  2 s.  c  o  m*/
    es.shutdown();
    while (!results.isEmpty()) {
        Iterator<Future<String>> i = results.iterator();
        while (i.hasNext()) {
            Future<String> f = i.next();
            if (f.isDone()) {
                System.out.println(f.get());
                i.remove();
            }
        }
    }
}

From source file:MainClass.java

public static void main(String[] args) {
    StopWatch stWatch = new StopWatch();

    //Start StopWatch
    stWatch.start();/*w  w w  .  j  a v  a  2 s  .  c o  m*/

    //Get iterator for all days in a week starting Monday
    Iterator itr = DateUtils.iterator(new Date(), DateUtils.RANGE_WEEK_MONDAY);

    while (itr.hasNext()) {
        Calendar gCal = (Calendar) itr.next();
        System.out.println(gCal.getTime());
    }

    //Stop StopWatch
    stWatch.stop();
    System.out.println("Time Taken >>" + stWatch.getTime());

}

From source file:XMLEventReaderDemo.java

public static void main(String[] args) throws Exception {
    XMLInputFactory factory = XMLInputFactory.newInstance();
    Reader fileReader = new FileReader("Source.xml");
    XMLEventReader reader = factory.createXMLEventReader(fileReader);

    while (reader.hasNext()) {
        XMLEvent event = reader.nextEvent();
        if (event.isStartElement()) {
            StartElement element = (StartElement) event;
            System.out.println("Start Element: " + element.getName());

            Iterator iterator = element.getAttributes();
            while (iterator.hasNext()) {
                Attribute attribute = (Attribute) iterator.next();
                QName name = attribute.getName();
                String value = attribute.getValue();
                System.out.println("Attribute name/value: " + name + "/" + value);
            }/*  w w  w.j av a 2 s  .  co m*/
        }
        if (event.isEndElement()) {
            EndElement element = (EndElement) event;
            System.out.println("End element:" + element.getName());
        }
        if (event.isCharacters()) {
            Characters characters = (Characters) event;
            System.out.println("Text: " + characters.getData());
        }
    }
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Selector selector = Selector.open();

    ServerSocketChannel ssChannel1 = ServerSocketChannel.open();
    ssChannel1.configureBlocking(false);
    ssChannel1.socket().bind(new InetSocketAddress(80));

    ServerSocketChannel ssChannel2 = ServerSocketChannel.open();
    ssChannel2.configureBlocking(false);
    ssChannel2.socket().bind(new InetSocketAddress(81));

    ssChannel1.register(selector, SelectionKey.OP_ACCEPT);
    ssChannel2.register(selector, SelectionKey.OP_ACCEPT);

    while (true) {
        selector.select();/*from   w w w .ja  v a2 s .  c  o  m*/
        Iterator it = selector.selectedKeys().iterator();
        while (it.hasNext()) {
            SelectionKey selKey = (SelectionKey) it.next();
            it.remove();

            if (selKey.isAcceptable()) {
                ServerSocketChannel ssChannel = (ServerSocketChannel) selKey.channel();
                SocketChannel sc = ssChannel.accept();
                ByteBuffer bb = ByteBuffer.allocate(100);
                sc.read(bb);

            }
        }
    }
}

From source file:json.ReadFromFile.java

public static void main(String[] args) {

    JSONParser parser = new JSONParser();
    try {//from   w ww.  j av  a 2s  .c o  m
        Object obj = parser.parse(new FileReader(file));
        JSONObject jsonObject = (JSONObject) obj;
        String countryName = jsonObject.get("Name") + "";//equivalent to jsonObject.get("Name").toString(); 
        System.out.println("Name of Country: " + countryName);

        long population = (long) jsonObject.get("Population");
        System.out.println("Population: " + population);

        System.out.println("Counties are:");
        JSONArray listOfCounties = (JSONArray) jsonObject.get("Counties");
        Iterator<String> iterator = listOfCounties.iterator();
        while (iterator.hasNext()) {
            System.out.println(iterator.next());
        }
    } catch (IOException | ParseException e) {
        e.printStackTrace();
    }
}

From source file:jsonpractice.jsonpractice1.java

public static void main(String[] args) throws IOException, ParseException {
    JSONParser parser = new JSONParser();
    try {/*  w ww  .  j  a  v  a2  s . c  om*/
        Object obj = parser.parse(new FileReader("C:\\Users\\user\\Documents\\CountryJSONFile.json"));
        JSONObject jsonobject = (JSONObject) obj;

        String nameOfCountry = (String) jsonobject.get("Name");
        System.out.println("Name of the Country: " + nameOfCountry);

        long population = (long) jsonobject.get("Population");
        System.out.println("Population of the country is : " + population);

        System.out.println("States are: ");
        JSONArray listOfStates = (JSONArray) jsonobject.get("states");

        Iterator<String> iterator = listOfStates.iterator();
        while (iterator.hasNext()) {
            System.out.println(iterator.next());
        }
    } catch (FileNotFoundException e) {
    } catch (IOException e) {
    } catch (ParseException e) {
    }

}