List of usage examples for java.util List size
int size();
From source file:Main.java
public static void main(String[] args) throws Exception { File xml = new File("yourFile.xml"); Document doc = (Document) new SAXBuilder().build(xml); Element rootNode = doc.getRootElement(); List list = rootNode.getChildren("staff"); XMLOutputter xmlOut = new XMLOutputter(); for (int i = 0; i < list.size(); i++) { Element node = (Element) list.get(i); if (node.getChildText("firstname").equals("sanjay")) node.getChild("salary").getChild("basic").setText("250000"); xmlOut.setFormat(Format.getPrettyFormat()); xmlOut.output(doc, new FileWriter("yourFile.xml")); }/*from www. ja va 2 s . c o m*/ }
From source file:Main.java
public static void main(String[] args) { String[] peoples = { "A", "B", "C", "D", "E", "F" }; List<String> names = Arrays.asList(peoples); for (int i = 0; i < peoples.length; i++) { int index = new Random().nextInt(names.size()); String anynames = names.get(index); System.out.println(anynames); }/* ww w . j a va 2 s . c o m*/ }
From source file:com.tomdoel.mpg2dcm.Mpg2Dcm.java
public static void main(String[] args) { try {/*from ww w . ja v a 2 s. c o m*/ final Options helpOptions = new Options(); helpOptions.addOption("h", false, "Print help for this application"); final DefaultParser parser = new DefaultParser(); final CommandLine commandLine = parser.parse(helpOptions, args); if (commandLine.hasOption('h')) { final String helpHeader = "Converts an mpeg2 video file to Dicom\n\n"; String helpFooter = "\nPlease report issues at github.com/tomdoel/mpg2dcm"; final HelpFormatter helpFormatter = new HelpFormatter(); helpFormatter.printHelp("Mpg2Dcm mpegfile dicomfile", helpHeader, helpOptions, helpFooter, true); } else { final List<String> remainingArgs = commandLine.getArgList(); if (remainingArgs.size() < 2) { throw new org.apache.commons.cli.ParseException("ERROR : Not enough arguments specified."); } final String mpegFileName = remainingArgs.get(0); final String dicomFileName = remainingArgs.get(1); final File mpegFile = new File(mpegFileName); final File dicomOutputFile = new File(dicomFileName); MpegFileConverter.convert(mpegFile, dicomOutputFile); } } catch (org.apache.commons.cli.ParseException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) { List<String> friends = Arrays.asList("A", "B", "C", "D"); //external iterate with index == evil for (int i = 0; i < friends.size(); i++) { System.out.println(friends.get(i)); }/*w w w . j ava 2 s . com*/ //external iterate on collection, better but ... external for (String friend : friends) { System.out.println(friend); } //lambda friends.forEach(s -> System.out.println(s)); //lambda reference friends.forEach(System.out::println); }
From source file:com.plexobject.testplayer.dao.hibernate.MethodStatsDaoHibernate.java
public static void main(String[] args) throws Exception { MethodStatsDaoHibernate dao = new MethodStatsDaoHibernate(); createTable();//from w w w. j av a2 s . co m for (int i = 0; i < 10; i++) { MethodStats method = new MethodStats("void main" + i + "(String[] args)", 2000 + i, 2000 + i, 2000 + i, 2000 + i, false, new Date()); dao.save(method); } /* */ List<MethodStats> list = dao.findAll(); System.out.println("Printing " + list.size() + ":\n" + list); if (list.size() > 0) { System.out.println("First " + dao.findById(list.get(0).getSignature())); } }
From source file:egovframework.standalone.SampleMain.java
public static void main(String[] args) { ApplicationContext context = new ClassPathXmlApplicationContext( new String[] { "classpath:/egovframework/spring/context-*.xml" }); EgovSampleService service = (EgovSampleService) context.getBean("sampleService"); SampleDefaultVO searchVO = new SampleDefaultVO(); try {/*ww w. j a v a2s.co m*/ List list = service.selectSampleList(searchVO); System.out.println("selectSampleList : " + list.size()); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:org.seasar.dao.spring.example.EmployeeAutoDaoClient.java
public static void main(final String[] args) { final BeanFactoryLocator locator = ContextSingletonBeanFactoryLocator.getInstance(); final BeanFactoryReference ref = locator.useBeanFactory("context"); final ApplicationContext context = (ApplicationContext) ref.getFactory(); try {// w w w .j av a 2 s. com final EmployeeAutoDao dao = (EmployeeAutoDao) context.getBean("employeeAutoDao"); dao.getEmployeeByJobDeptno(null, null); dao.getEmployeeByJobDeptno("CLERK", null); dao.getEmployeeByJobDeptno(null, new Integer(20)); dao.getEmployeeByJobDeptno("CLERK", new Integer(20)); List employees = dao.getEmployeesBySal(0, 1000); for (int i = 0; i < employees.size(); ++i) { System.out.println(employees.get(i)); } employees = dao.getEmployeeByDname("SALES"); for (int i = 0; i < employees.size(); ++i) { System.out.println(employees.get(i)); } final EmployeeSearchCondition dto = new EmployeeSearchCondition(); dto.setDname("RESEARCH"); employees = dao.getEmployeesBySearchCondition(dto); for (int i = 0; i < employees.size(); ++i) { System.out.println(employees.get(i)); } final Employee employee = dao.getEmployeeByEmpno(7788); System.out.println("before timestamp:" + employee.getTimestamp()); dao.update(employee); System.out.println("after timestamp:" + employee.getTimestamp()); } finally { ref.release(); } }
From source file:au.org.ala.layers.client.Client.java
public static void main(String[] args) { System.out.println("Layers Store CLI client"); ApplicationContext context = new ClassPathXmlApplicationContext("spring/app-config.xml"); LayerDAO layerDao = (LayerDAO) context.getBean("layerDao"); List<Layer> layers = layerDao.getLayers(); System.out.println("Got " + layers.size() + " layers"); Iterator<Layer> it = layers.iterator(); while (it.hasNext()) { Layer l = it.next();/* ww w. j a va 2s . c om*/ System.out.println(" > " + l.getName()); } }
From source file:Main.java
public static void main(String[] args) { Integer[] arr = { 1, 2, 3, 1, 4, 4, 1, 5 }; System.out.println(Arrays.toString(arr)); List<Integer> l = Arrays.asList(arr); System.out.println(l);/*from www.j a va 2s .c o m*/ Set<Integer> set = new HashSet<Integer>(); for (int j = 0; j < l.size(); j++) { if (Collections.frequency(l, l.get(j)) > 1) { set.add(l.get(j)); } } System.out.println("dups are:" + set); }
From source file:Test.java
public static void main(String[] args) { RuntimeMXBean mxBean = ManagementFactory.getPlatformMXBean(RuntimeMXBean.class); System.out.println("JVM Name: " + mxBean.getName()); System.out.println("JVM Specification Name: " + mxBean.getSpecName()); System.out.println("JVM Specification Version: " + mxBean.getSpecVersion()); System.out.println("JVM Implemenation Name: " + mxBean.getVmName()); System.out.println("JVM Implemenation Vendor: " + mxBean.getVmVendor()); System.out.println("JVM Implemenation Version: " + mxBean.getVmVersion()); // Using the getPlatformMXBeans method List<OperatingSystemMXBean> list = ManagementFactory.getPlatformMXBeans(OperatingSystemMXBean.class); System.out.println("size: " + list.size()); for (OperatingSystemMXBean bean : list) { System.out.println("Operating System Name: " + bean.getName()); System.out.println("Operating System Architecture: " + bean.getArch()); System.out.println("Operating System Version: " + bean.getVersion()); }/* www. j a v a 2 s .c o m*/ }