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[] argv) {
    List<String> list = new ArrayList<String>();
    list.add("A");
    list.add("2");
    list.add("c2");

    System.out.println(countDistinctElements(list, 0, list.size()));
}

From source file:org.voltdb.example.springjdbc.SpringJDBCTemplateTest.java

public static void main(String[] args) throws Exception {

    GenericApplicationContext ctx = new GenericXmlApplicationContext("/applicationContext.xml");
    BeanFactory factory = ctx;//from   w ww .  j a  v  a2  s  .  c o m
    ContestantDao contestantDao = (ContestantDao) factory.getBean("contestantDao");

    List<ContestantData> list = contestantDao.findContestant("0");
    if (list == null || list.size() == 0) {
        contestantDao.insertContestant("foo", "bar", "0");
    }
    list = contestantDao.findContestant("0");
    if (list.size() == 1) {
        System.out.println("Insert Success");
        ContestantData d = list.get(0);
        if (!d.getCode().equals("0") || !d.getFirstName().equals("foo") || !d.getLastName().equals("bar")) {
            System.out.println("Insert failed");
        }
    }
    contestantDao.updateContestant("foo2", "bar2", "0");
    list = contestantDao.findContestant("0");
    if (list.size() == 1) {
        System.out.println("Update Success");
        ContestantData d = list.get(0);
        if (!d.getCode().equals("0") || !d.getFirstName().equals("foo2") || !d.getLastName().equals("bar2")) {
            System.out.println("Update faild");
        }
    }

    contestantDao.insertContestant(null, null, "1");
    list = contestantDao.getAllContestants();
    if (list.size() == 2) {
        System.out.println("Get All Successful.");
    }

    contestantDao.deleteContestant("1");
    System.out.println("Delete was Successful.");
    contestantDao.insertContestant(null, null, "1");
    contestantDao.deleteAllContestants();
    System.out.println("Delete All was Successful.");
}

From source file:Main.java

public static void main(String[] args) {
    List<String> list = new LinkedList<String>();
    list.add("A");
    list.add("B");
    list.add("C");
    list.add("D");

    String[] colors = new String[list.size()];
    list.toArray(colors);//from  www .  j a  va2  s .c om

    for (int i = 0; i < colors.length; i++) {
        System.out.println("color = " + colors[i]);
    }
}

From source file:MainClass.java

public static void main(String[] a) {

    List list = new LinkedList();
    list.add("A");
    list.add("B");
    list.add("C");
    list.add("D");

    ListIterator iter = list.listIterator(list.size());

    while (iter.hasPrevious()) {
        System.out.println(iter.previous());
        iter.add("a");
        break;/* w ww .ja v a2s  .c  om*/
    }
    System.out.println(list);
}

From source file:test.AsyncClientCustomContext.java

public final static void main(String[] args) throws Exception {
    CloseableHttpAsyncClient httpclient = HttpAsyncClients.createDefault();
    HttpEntity entity = null;//from   ww  w  . ja  va 2  s . co m
    String jsonContent = "";
    try {
        // Create a local instance of cookie store
        CookieStore cookieStore = new BasicCookieStore();

        // Create local HTTP context
        HttpClientContext localContext = HttpClientContext.create();
        // Bind custom cookie store to the local context
        localContext.setCookieStore(cookieStore);

        HttpGet httpget = new HttpGet("http://viphp.sinaapp.com/baidu/translate/translate.php?origin=");
        System.out.println("Executing request " + httpget.getRequestLine());

        httpclient.start();

        // Pass local context as a parameter
        Future<HttpResponse> future = httpclient.execute(httpget, localContext, null);

        // Please note that it may be unsafe to access HttpContext instance
        // while the request is still being executed
        HttpResponse response = future.get();
        System.out.println("Response: " + response.getStatusLine());
        entity = response.getEntity();
        jsonContent = EntityUtils.toString(entity, "UTF-8");
        System.out.println("jsonContent:" + jsonContent);
        List<Cookie> cookies = cookieStore.getCookies();
        for (int i = 0; i < cookies.size(); i++) {
            System.out.println("Local cookie: " + cookies.get(i));
        }
        System.out.println("Shutting down");
    } finally {
        httpclient.close();
    }
}

From source file:MainClass.java

public static void main(String args[]) {
    String str[] = { "B", "H", "L", "M", "I", "N", "R" };
    // Convert to list
    List list = new ArrayList(Arrays.asList(str));
    // Ensure list sorted
    Collections.sort(list);// w  ww  . j  a  v  a  2  s .  com
    System.out.println("Sorted list: [length: " + list.size() + "]");
    System.out.println(list);
    // Search for element in list
    int index = Collections.binarySearch(list, "M");
    System.out.println("Found M @ " + index);
    // Search for element not in list
    index = Collections.binarySearch(list, "J");
    System.out.println("Didn't find J @ " + index);
    // Insert
    int newIndex = -index - 1;
    list.add(newIndex, "J");
    System.out.println("With J added: [length: " + list.size() + "]");
    System.out.println(list);
}

From source file:MainClass.java

public static void main(String[] a) {
    List list = new ArrayList(10);
    Object anObject = "A";
    list.add("N");
    Collections.fill(list, anObject);
    System.out.println(list);//from  w w  w .ja v a  2 s .  c o  m
    System.out.println(list.size());
}

From source file:com.hilatest.httpclient.apacheexample.ClientCustomContext.java

public final static void main(String[] args) throws Exception {

    HttpClient httpclient = new DefaultHttpClient();

    // Create a local instance of cookie store
    CookieStore cookieStore = new BasicCookieStore();

    // Create local HTTP context
    HttpContext localContext = new BasicHttpContext();
    // Bind custom cookie store to the local context
    localContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);

    HttpGet httpget = new HttpGet("http://www.google.com/");

    System.out.println("executing request " + httpget.getURI());

    // Pass local context as a parameter
    HttpResponse response = httpclient.execute(httpget, localContext);
    HttpEntity entity = response.getEntity();

    System.out.println("----------------------------------------");
    System.out.println(response.getStatusLine());
    if (entity != null) {
        System.out.println("Response content length: " + entity.getContentLength());
    }/* ww  w  . ja  va 2s.c o  m*/
    List<Cookie> cookies = cookieStore.getCookies();
    for (int i = 0; i < cookies.size(); i++) {
        System.out.println("Local cookie: " + cookies.get(i));
    }

    // Consume response content
    if (entity != null) {
        entity.consumeContent();
    }

    System.out.println("----------------------------------------");

    // When HttpClient instance is no longer needed, 
    // shut down the connection manager to ensure
    // immediate deallocation of all system resources
    httpclient.getConnectionManager().shutdown();
}

From source file:com.mama100.android.member.http.ClientCustomContext.java

public final static void main(String[] args) throws Exception {

    HttpClient httpclient = new DefaultHttpClient();

    // Create a local instance of cookie store
    CookieStore cookieStore = new BasicCookieStore();

    // Create local HTTP context
    HttpContext localContext = new BasicHttpContext();
    // Bind custom cookie store to the local context
    localContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);

    HttpGet httpget = new HttpGet("http://www.weibo.com/");

    System.out.println("executing request " + httpget.getURI());

    // Pass local context as a parameter
    HttpResponse response = httpclient.execute(httpget, localContext);
    HttpEntity entity = response.getEntity();

    System.out.println("----------------------------------------");
    System.out.println(response.getStatusLine());
    if (entity != null) {
        System.out.println("Response content length: " + entity.getContentLength());
    }/*from w w w .  j  av  a 2  s .c om*/
    List<Cookie> cookies = cookieStore.getCookies();
    for (int i = 0; i < cookies.size(); i++) {
        System.out.println("Local cookie: " + cookies.get(i));
    }

    // Consume response content
    if (entity != null) {
        entity.consumeContent();
    }

    System.out.println("----------------------------------------");

    // When HttpClient instance is no longer needed, 
    // shut down the connection manager to ensure
    // immediate deallocation of all system resources
    httpclient.getConnectionManager().shutdown();
}

From source file:com.dlmu.heipacker.crawler.client.ClientCustomContext.java

public final static void main(String[] args) throws Exception {

    HttpClient httpclient = new DefaultHttpClient();
    try {/*from w  w  w. j av  a2s .  com*/
        // Create a local instance of cookie store
        CookieStore cookieStore = new BasicCookieStore();

        // Create local HTTP context
        HttpContext localContext = new BasicHttpContext();
        // Bind custom cookie store to the local context
        localContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);

        HttpGet httpget = new HttpGet("http://www.google.com/");

        System.out.println("executing request " + httpget.getURI());

        // Pass local context as a parameter
        HttpResponse response = httpclient.execute(httpget, localContext);
        HttpEntity entity = response.getEntity();

        System.out.println("----------------------------------------");
        System.out.println(response.getStatusLine());
        if (entity != null) {
            System.out.println("Response content length: " + entity.getContentLength());
        }
        List<Cookie> cookies = cookieStore.getCookies();
        for (int i = 0; i < cookies.size(); i++) {
            System.out.println("Local cookie: " + cookies.get(i));
        }

        // Consume response content
        EntityUtils.consume(entity);

        System.out.println("----------------------------------------");

    } finally {
        // When HttpClient instance is no longer needed,
        // shut down the connection manager to ensure
        // immediate deallocation of all system resources
        httpclient.getConnectionManager().shutdown();
    }
}