Example usage for java.util List size

List of usage examples for java.util List size

Introduction

In this page you can find the example usage for java.util List size.

Prototype

int size();

Source Link

Document

Returns the number of elements in this list.

Usage

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 + ", ");
        }/*w  w  w. j a v a  2s . c o  m*/
    }
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    String xml = "<?xml version='1.0' encoding='UTF-8'?>" + "<Employees>"
            + "  <Employee emplid='1' type='admin'>" + "    <firstname/>" + "    <lastname>A</lastname>"
            + "    <age>30</age>" + "    <email>j@s.com</email>" + "  </Employee>"
            + "  <Employee emplid='2' type='admin'>" + "    <firstname>S</firstname>"
            + "    <lastname>H</lastname>" + "    <age>32</age>" + "    <email>s@h.com</email>"
            + "  </Employee>" + "</Employees>";
    List<String> ids = Arrays.asList("1", "2");
    for (int i = 0; i < ids.size(); i++) {
        String employeeId = ids.get(i);
        String xpath = "/Employees/Employee[@emplid='" + employeeId + "']/firstname";
        XPath xPath = XPathFactory.newInstance().newXPath();
        String employeeFirstName = xPath.evaluate(xpath, new InputSource(new StringReader(xml)));
        if (employeeFirstName == "") {
            System.out.println("Employee " + employeeId + " has no first name.");
        } else {//from  w w w. j ava2s .c  o  m
            System.out.println("Employee " + employeeId + "'s first name is " + employeeFirstName);
        }
    }
}

From source file:MainClass.java

public static void main(String args[]) throws Exception {
    List list = Arrays.asList("a", "c", "b");
    Collections.sort(list);/*from  ww  w  . j a v a2  s  .c  o m*/
    for (int i = 0, n = list.size(); i < n; i++) {
        if (i != 0)
            System.out.print(", ");
        System.out.print(list.get(i));
    }
    System.out.println();
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    List drivers = Collections.list(DriverManager.getDrivers());
    for (int i = 0; i < drivers.size(); i++) {
        Driver driver = (Driver) drivers.get(i);

        String name = driver.getClass().getName();
        System.out.println(name);

        int majorVersion = driver.getMajorVersion();
        System.out.println(majorVersion);
        int minorVersion = driver.getMinorVersion();
        System.out.println(minorVersion);
        boolean isJdbcCompliant = driver.jdbcCompliant();
        System.out.println(isJdbcCompliant);
    }//w ww  . j a v a2 s .  c  o  m
}

From source file:Main.java

public static void main(String[] args) {
    String data = "<root><row><column name='username' length='6'>admin</column>"
            + "<column name='password' length='1'>p</column></row><row>"
            + "<column name='username' length='6'>j</column>"
            + "<column name='password' length='8'>q</column></row></root>";

    SAXBuilder builder = new SAXBuilder();
    Document document = builder.build(new ByteArrayInputStream(data.getBytes()));

    Element root = document.getRootElement();

    List rows = root.getChildren("row");
    for (int i = 0; i < rows.size(); i++) {
        Element row = (Element) rows.get(i);
        List columns = row.getChildren("column");
        for (int j = 0; j < columns.size(); j++) {
            Element column = (Element) columns.get(j);
            String name = column.getAttribute("name").getValue();
            String value = column.getText();
            int length = column.getAttribute("length").getIntValue();

            System.out.println("name = " + name);
            System.out.println("value = " + value);
            System.out.println("length = " + length);
        }/* w  w w .ja  v a 2s. c  o m*/
    }
}

From source file:Main.java

License:asdf

public static void main(String[] args) {
    String diagonal = "asdf";
    List<String> permutations = allPermutation("", diagonal);
    System.out.println("size is : " + permutations.size());
    System.out.println(permutations);
}

From source file:org.seasar.dao.spring.example.Employee2DaoClient.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 {/*from ww w . j av  a2s  . c o m*/
        final Employee2Dao dao = (Employee2Dao) context.getBean("employee2Dao");
        final List employees = dao.getEmployees("CO");
        for (int i = 0; i < employees.size(); ++i) {
            System.out.println(employees.get(i));
        }
        final Employee employee = dao.getEmployee(7788);
        System.out.println(employee);
    } finally {
        ref.release();
    }

}

From source file:MainClass.java

License:asdf

public static void main(String[] args) throws Exception {
    String characterName = "asdf";
    SAXBuilder builder = new SAXBuilder();
    Document document = builder.build(new File("r.xml"));
    List actList = document.getRootElement().getChildren("ACT");
    allDone: for (int act = 0; act < actList.size(); act++) {
        List sceneList = ((Element) actList.get(act)).getChildren("SCENE");
        for (int scene = 0; scene < sceneList.size(); scene++) {
            List speechList = ((Element) sceneList.get(scene)).getChildren("SPEECH");
            for (int speech = 0; speech < speechList.size(); speech++) {
                if (characterName
                        .equalsIgnoreCase(((Element) speechList.get(speech)).getChildText("SPEAKER"))) {
                    System.out.println(characterName);
                    break allDone;
                }/*  ww w  .  j a  v  a 2s  . co  m*/
            }
        }
    }
}

From source file:Main.java

public static void main(String[] args) {
    List<String> stringList = Arrays.asList(args);
    System.out.println("before: " + stringList);
    for (int i = 0; i < stringList.size(); ++i) {
        stringList.set(i, stringList.get(i).replaceAll("\\s+", ""));
    }/*from w w  w  . j  a  va  2  s . c  o  m*/
    System.out.println("after : " + stringList);
}

From source file:io.github.carlomicieli.springbooks.MainClass.java

public static void main(String[] args) {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ApplicationConfig.class);
    //        ctx.getEnvironment().setActiveProfiles("default");
    //        ctx.register(ApplicationConfig.class);
    //        ctx.refresh();

    log.info("Running sample application...");
    InitService s = ctx.getBean("initService", InitService.class);

    log.info("Dropping books collection...");
    s.dropBooks();/*from  w w w .  jav  a2s.c o m*/

    log.info("Init books collection...");
    s.initBooks();

    BookService s2 = ctx.getBean(BookService.class);
    List<Book> books = s2.findByCommentAuthor("Jane Doe");

    System.out.println(books.size());
}