List of usage examples for java.util Map keySet
Set<K> keySet();
From source file:Main.java
public static void main(String[] args) throws Exception { URL url = new URL("http://www.google.com/index.html"); URLConnection connection = url.openConnection(); Map responseMap = connection.getHeaderFields(); for (Iterator iterator = responseMap.keySet().iterator(); iterator.hasNext();) { String key = (String) iterator.next(); System.out.println(key + " = "); List values = (List) responseMap.get(key); for (int i = 0; i < values.size(); i++) { Object o = values.get(i); System.out.println(o + ", "); }//from w ww . ja v a 2 s. c o m } }
From source file:MainClass.java
public static void main(String[] args) throws Exception { Document document = new Document(new Rectangle(100, 100)); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("sun_tutorial_with_text.pdf")); document.open();//from w ww. j a va2s . c o m PdfContentByte cb = writer.getDirectContent(); PdfTemplate tp = cb.createTemplate(100, 100); DefaultFontMapper mapper = new DefaultFontMapper(); mapper.insertDirectory("c:/windows/fonts"); String name; Map map = mapper.getMapper(); for (Iterator i = map.keySet().iterator(); i.hasNext();) { name = (String) i.next(); System.out.println(name + ": " + ((DefaultFontMapper.BaseFontParameters) map.get(name)).fontName); } Graphics2D g2 = tp.createGraphics(100, 100, mapper); g2.setColor(Color.black); java.awt.Font thisFont = new java.awt.Font("Garamond", java.awt.Font.PLAIN, 18); g2.setFont(thisFont); String pear = "Pear"; FontMetrics metrics = g2.getFontMetrics(); int width = metrics.stringWidth(pear); g2.drawString(pear, (100 - width) / 2, 20); g2.dispose(); cb.addTemplate(tp, 0, 0); document.close(); }
From source file:Main.java
public static void main(String[] argv) { List collection = new ArrayList(); // For a set or list for (Iterator it = collection.iterator(); it.hasNext();) { Object element = it.next(); }/*from www. j a v a 2 s. co m*/ Map map = new HashMap(); // For keys of a map for (Iterator it = map.keySet().iterator(); it.hasNext();) { Object key = it.next(); } // For values of a map for (Iterator it = map.values().iterator(); it.hasNext();) { Object value = it.next(); } // For both the keys and values of a map for (Iterator it = map.entrySet().iterator(); it.hasNext();) { Map.Entry entry = (Map.Entry) it.next(); Object key = entry.getKey(); Object value = entry.getValue(); } }
From source file:com.joshlong.examples.data.counter.Main.java
public static void main(String[] args) throws Throwable { ApplicationContext ac = new ClassPathXmlApplicationContext("classpath:/counter.xml"); Map<String, Counter> counters = ac.getBeansOfType(Counter.class); for (String beanName : counters.keySet()) exercise(beanName, counters.get(beanName)); }
From source file:com.apress.prospringintegration.jdbc.JdbcGateway.java
public static void main(String[] args) throws Exception { ApplicationContext context = new ClassPathXmlApplicationContext("/spring/jdbc/jdbc-gateway-context.xml"); MessageChannel input = context.getBean("input", MessageChannel.class); PollableChannel output = context.getBean("output", PollableChannel.class); Map<String, Object> rowMessage = new HashMap<String, Object>(); rowMessage.put("id", 3); rowMessage.put("firstname", "Mr"); rowMessage.put("lastname", "Bill"); rowMessage.put("status", 0); Message<Map<String, Object>> message = MessageBuilder.withPayload(rowMessage).build(); input.send(message);/*ww w. j a v a 2 s. c o m*/ Message<?> reply = output.receive(); System.out.println("Reply message: " + reply); Map<String, Object> rowMap = (Map<String, Object>) reply.getPayload(); for (String column : rowMap.keySet()) { System.out.println("column: " + column + " value: " + rowMap.get(column)); } }
From source file:Main.java
public static void main(String[] argv) throws Exception { Map weakMap = new WeakHashMap(); Object keyObject = ""; Object valueObject = ""; weakMap.put(keyObject, valueObject); Iterator it = weakMap.keySet().iterator(); while (it.hasNext()) { Object key = it.next();/* w w w . j ava2 s .c o m*/ } }
From source file:edu.sjsu.cmpe275.lab2.model.HibernateUtil.java
public static void main(final String[] args) throws Exception { Session session = getSessionFactory().openSession(); try {//from w w w . ja v a 2 s . com System.out.println("querying all the managed entities..."); final Map metadataMap = session.getSessionFactory().getAllClassMetadata(); for (Object key : metadataMap.keySet()) { final ClassMetadata classMetadata = (ClassMetadata) metadataMap.get(key); final String entityName = classMetadata.getEntityName(); final Query query = session.createQuery("from " + entityName); System.out.println("executing: " + query.getQueryString()); for (Object o : query.list()) { System.out.println(" " + o); } } } finally { session.close(); } }
From source file:DiameterMap.java
public static void main(String args[]) { String names[] = { "Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune", "Pluto" }; float diameters[] = { 4800f, 12103.6f, 12756.3f, 6794f, 142984f, 120536f, 51118f, 49532f, 2274f }; Map map = new TreeMap(); for (int i = 0, n = names.length; i < n; i++) { map.put(names[i], new Float(diameters[i])); }/* w w w. ja va2 s. c o m*/ Iterator it = map.keySet().iterator(); Object obj; while (it.hasNext()) { obj = it.next(); System.out.println(obj + ": " + map.get(obj)); } }
From source file:gov.nih.nci.cabio.portal.portlet.canned.CannedObjectConfig.java
/** * Test harness.//w w w.ja v a 2 s .co m */ public static final void main(String[] args) throws Exception { CannedObjectConfig c = new CannedObjectConfig(); Map<String, ClassObject> classes = c.getClasses(); for (String className : classes.keySet()) { ClassObject config = classes.get(className); System.out.println(className + ": " + config.getLabel()); for (LabeledObject attr : config.getAttributesForRole("SUMMARY")) { System.out.println("\t" + attr.getName() + ": " + attr.getLabel()); } } }
From source file:MainClass.java
public static void main(String[] a) { Map map = new HashMap(); map.put("key1", "value1"); map.put("key2", "value2"); map.put("key3", "value3"); map.put(null, null);/* w w w . j a v a 2 s . com*/ Set set = map.keySet(); Iterator iter = set.iterator(); while (iter.hasNext()) { System.out.println(iter.next()); } }