List of usage examples for java.util Iterator hasNext
boolean hasNext();
From source file:Main.java
public static void main(String[] args) { ArrayList<String> list = new ArrayList<String>(); list.add("Monday"); list.add("Tuesdag"); list.add("Wednesday"); list.add("Thursday"); list.add("Friday"); list.add("Saturday"); list.add("Sunday"); Iterator<String> iterator = null; iterator = list.iterator();/*from w w w. ja v a 2s.co m*/ while (iterator.hasNext()) { String element = iterator.next(); System.out.println(element); } for (iterator = list.iterator(); iterator.hasNext();) { String element = iterator.next(); System.out.println(element); } for (String element : list) { System.out.println(element); } }
From source file:Main.java
public static void main(String[] argv) throws Exception { ImageInputStream imageStream = ImageIO.createImageInputStream(new URL("").openStream()); Iterator<ImageReader> readers = ImageIO.getImageReaders(imageStream); ImageReader reader = null;// w w w . j ava 2 s. com if (!readers.hasNext()) { imageStream.close(); return; } else { reader = readers.next(); } String formatName = reader.getFormatName(); if (!formatName.equalsIgnoreCase("jpeg") && !formatName.equalsIgnoreCase("png") && !formatName.equalsIgnoreCase("gif")) { imageStream.close(); return; } reader.setInput(imageStream, true, true); BufferedImage theImage = reader.read(0); reader.dispose(); imageStream.close(); }
From source file:au.org.ands.vocabs.toolkit.db.DumpAccessPointsData.java
/** * Main program./*from w ww .j a v a 2 s.co m*/ * @param args Command-line arguments */ public static void main(final String[] args) { List<AccessPoint> aps = AccessPointUtils.getAllAccessPoints(); for (AccessPoint ap : aps) { System.out.println(ap.getId()); System.out.println(ap.getVersionId()); System.out.println(ap.getType()); String pd = ap.getPortalData(); String td = ap.getToolkitData(); System.out.println("portal_data:"); JsonNode pdJson = TaskUtils.jsonStringToTree(pd); Iterator<Entry<String, JsonNode>> pdJsonIterator = pdJson.fields(); while (pdJsonIterator.hasNext()) { Entry<String, JsonNode> entry = pdJsonIterator.next(); System.out.println(entry.getKey() + "=" + entry.getValue().asText()); } System.out.println("toolkit_data:"); JsonNode tdJson = TaskUtils.jsonStringToTree(td); Iterator<Entry<String, JsonNode>> tdJsonIterator = tdJson.fields(); while (tdJsonIterator.hasNext()) { Entry<String, JsonNode> entry = tdJsonIterator.next(); System.out.println(entry.getKey() + "=" + entry.getValue().asText()); } } }
From source file:cat.tv3.eng.rec.recomana.lupa.visualization.RecommendationToJson.java
public static void main(String[] args) throws IOException { final int TOTAL_WORDS = 20; String host = args[0];//from w w w .j a v a 2 s . c o m int port = Integer.parseInt(args[1]); Jedis jedis = new Jedis(host, port, 20000); String[] recommendation_keys = jedis.keys("recommendations_*").toArray(new String[0]); for (int i = 0; i < recommendation_keys.length; ++i) { JSONArray recommendations = new JSONArray(); String[] split_reco_name = recommendation_keys[i].split("_"); String id = split_reco_name[split_reco_name.length - 1]; Set<Tuple> recos = jedis.zrangeWithScores(recommendation_keys[i], 0, -1); Iterator<Tuple> it = recos.iterator(); while (it.hasNext()) { Tuple t = it.next(); JSONObject new_reco = new JSONObject(); new_reco.put("id", t.getElement()); new_reco.put("distance", (double) Math.round(t.getScore() * 10000) / 10000); recommendations.add(new_reco); } saveResults(recommendations, id); } jedis.disconnect(); }
From source file:LinkedListTest.java
public static void main(String[] args) { List<String> a = new LinkedList<String>(); a.add("Amy"); a.add("Carl"); a.add("Erica"); List<String> b = new LinkedList<String>(); b.add("Bob"); b.add("Doug"); b.add("Frances"); b.add("Gloria"); // merge the words from b into a ListIterator<String> aIter = a.listIterator(); Iterator<String> bIter = b.iterator(); while (bIter.hasNext()) { if (aIter.hasNext()) aIter.next();/*from w w w . j a va 2 s. c o m*/ aIter.add(bIter.next()); } System.out.println(a); // remove every second word from b bIter = b.iterator(); while (bIter.hasNext()) { bIter.next(); // skip one element if (bIter.hasNext()) { bIter.next(); // skip next element bIter.remove(); // remove that element } } System.out.println(b); // bulk operation: remove all words in b from a a.removeAll(b); System.out.println(a); }
From source file:Main.java
public static void main(String[] args) throws IOException { URL[] urls = { new URL("http://yourserver/small.png") }; for (URL url : urls) { ImageInputStream iis = ImageIO.createImageInputStream(url.openStream()); Iterator<ImageReader> readers = ImageIO.getImageReaders(iis); System.out.println("url= " + url.getPath()); while (readers.hasNext()) { ImageReader read = readers.next(); System.out.println("format name = " + read.getFormatName()); }//from ww w. j a v a2s. c o m System.out.println(); } }
From source file:chat.jsonTest.java
/** * @param args the command line arguments *//*from w w w. j a v a2 s . c om*/ public static void main(String[] args) throws ParseException, IOException { // TODO code application logic here JSONParser parser = new JSONParser(); String fullPath = "userInfo.json"; //BufferedReader reader = new BufferedReader(new FileReader(fullPath)); Object obj = parser.parse(new FileReader("userInfo.json")); JSONObject jsonObject = (JSONObject) obj; /*while ((line = reader.readLine()) != null) { System.out.println(line); }*/ JSONArray lang = (JSONArray) jsonObject.get("userInfo"); Iterator i = lang.iterator(); // take each value from the json array separately while (i.hasNext()) { JSONObject innerObj = (JSONObject) i.next(); System.out .println("username " + innerObj.get("username") + " with password " + innerObj.get("password")); } }
From source file:be.dnsbelgium.rdap.client.ManGenerator.java
public static void main(String[] args) { Options options = new RDAPOptions(Locale.ENGLISH); Iterator<Option> it = options.getOptions().iterator(); StringBuilder sb = new StringBuilder(); while (it.hasNext()) { Option option = it.next(); sb.append(String.format(".IP \"%s\"\n%s\n", getOptionString(option), option.getDescription() == null ? "" : option.getDescription())); }/*from w w w. j ava 2 s. c o m*/ System.out.println(sb.toString()); }
From source file:CAList.java
/** * <p><!-- Method description --></p> * * * @param args/*w ww . ja v a 2s .c o m*/ */ public static void main(String[] args) { try { // Load the JDK's cacerts keystore file String filename = System.getProperty("java.home") + "/lib/security/cacerts".replace('/', File.separatorChar); FileInputStream is = new FileInputStream(filename); KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType()); String password = "changeit"; keystore.load(is, password.toCharArray()); // This class retrieves the most-trusted CAs from the keystore PKIXParameters params = new PKIXParameters(keystore); // Get the set of trust anchors, which contain the most-trusted CA certificates Iterator it = params.getTrustAnchors().iterator(); for (; it.hasNext();) { TrustAnchor ta = (TrustAnchor) it.next(); // Get certificate X509Certificate cert = ta.getTrustedCert(); System.out.println("<issuer>" + cert.getIssuerDN() + "</issuer>\n"); } } catch (CertificateException e) { } catch (KeyStoreException e) { } catch (NoSuchAlgorithmException e) { } catch (InvalidAlgorithmParameterException e) { } catch (IOException e) { } }
From source file:Main.java
public static void main(String[] args) { ArrayList<String> aList = new ArrayList<String>(); aList.add("1"); aList.add("2"); aList.add("3"); aList.add("4"); aList.add("5"); Iterator itr = aList.iterator(); // iterate through the ArrayList values using Iterator's hasNext and next methods while (itr.hasNext()) { System.out.println(itr.next()); }/*from ww w. j a va2s . com*/ }