Example usage for java.util ArrayList add

List of usage examples for java.util ArrayList add

Introduction

In this page you can find the example usage for java.util ArrayList add.

Prototype

public boolean add(E e) 

Source Link

Document

Appends the specified element to the end of this list.

Usage

From source file:eu.seaclouds.platform.planner.core.PlannerClient.java

public static void main(String[] args) throws IOException {
    ArrayList<NameValuePair> params = new ArrayList<>();
    params.add(new BasicNameValuePair("aam", "test http healper"));

    String content = new HttpHelper("http://localhost:8080").getRequest("/plan", params);
    System.out.println(content);/*from   w ww .j a  va  2 s .  com*/

    content = new HttpHelper("http://localhost:8080").postRequest("/plan", params);
    System.out.println("POST!!!! " + content);

    //        CloseableHttpClient httpclient = HttpClients.createDefault();
    //
    //
    //        HttpGet hhtpGet = new HttpGet("http://localhost:8080/plan?aam=qwerty");
    //
    //
    //        CloseableHttpResponse response2 = httpclient.execute(hhtpGet);
    //
    ////        HttpPost httpPost = new HttpPost("http://targethost/login");
    ////        List <NameValuePair> nvps = new ArrayList <NameValuePair>();
    ////        nvps.add(new BasicNameValuePair("username", "vip"));
    ////        nvps.add(new BasicNameValuePair("password", "secret"));
    ////        httpPost.setEntity(new UrlEncodedFormEntity(nvps));
    ////        CloseableHttpResponse response2 = httpclient.execute(httpPost);
    //
    //        try {
    //            //System.out.println(response2.getStatusLine());
    //            HttpEntity entity2 = response2.getEntity();
    //            // do something useful with the response body
    //            // and ensure it is fully consumed
    //
    //            String content = new Scanner(entity2.getContent()).useDelimiter("\\Z").next();
    //            System.out.println(content);
    //
    //            EntityUtils.consume(entity2);
    //        } finally {
    //            response2.close();
    //        }
}

From source file:com.github.xbn.examples.io.non_xbn.SizeOrderAllFilesInDirXmpl.java

public static final void main(String[] ignored) {
    File fDir = (new File("R:\\jeffy\\programming\\sandbox\\xbnjava\\xbn\\"));
    Collection<File> cllf = FileUtils.listFiles(fDir, (new String[] { "java" }), true);

    //Add all file paths to a Map, keyed by size.
    //It's actually a map of lists-of-files, to
    //allow multiple files that happen to have the
    //same length.

    TreeMap<Long, List<File>> tmFilesBySize = new TreeMap<Long, List<File>>();
    Iterator<File> itrf = cllf.iterator();
    while (itrf.hasNext()) {
        File f = itrf.next();/*www .  jav  a  2s.  c  o  m*/
        Long LLen = f.length();
        if (!tmFilesBySize.containsKey(LLen)) {
            ArrayList<File> alf = new ArrayList<File>();
            alf.add(f);
            tmFilesBySize.put(LLen, alf);
        } else {
            tmFilesBySize.get(LLen).add(f);
        }
    }

    //Iterate backwards by key through the map. For each
    //List<File>, iterate through the files, printing out
    //its size and path.

    ArrayList<Long> alSize = new ArrayList<Long>(tmFilesBySize.keySet());
    for (int i = alSize.size() - 1; i >= 0; i--) {
        itrf = tmFilesBySize.get(alSize.get(i)).iterator();
        while (itrf.hasNext()) {
            File f = itrf.next();
            System.out.println(f.length() + ": " + f.getPath());
        }
    }
}

From source file:dataflow.examples.DockerClientExample.java

public static void main(String[] args) throws IOException, DockerException, InterruptedException {
    String localTempDir = createLocalTempDir();
    String dockerAddress = "unix:///var/run/docker.sock";
    String dockerImage = "ubuntu:latest";
    DockerClient dockerClient = new DefaultDockerClient(dockerAddress);
    String localInput = FilenameUtils.concat(localTempDir, "file_on_host.txt");

    PrintStream stream = new PrintStream(localInput);
    stream.append("\nHello from the host machine.\n");
    stream.close();/*from ww w .  j  ava  2  s . c o  m*/

    // Run a simple command in the container to demonstrate we can read the
    // file mounted from the host.
    ArrayList<String> command = new ArrayList<String>();
    command.add("cat");
    command.add("/mounted/file_on_host.txt");

    DockerProcessBuilder builder = new DockerProcessBuilder(command, dockerClient);
    builder.addVolumeMapping(localTempDir, "/mounted");
    builder.setImage(dockerImage);

    // Start and run the container.
    builder.start();
}

From source file:Main.java

public static void main(String args[]) {
    ArrayList<String> al = new ArrayList<String>();

    System.out.println("Initial size of al: " + al.size());

    al.add("C");
    al.add("A");//from  w  ww . j ava  2s .co m
    al.add("E");
    al.add("B");
    al.add("D");
    al.add("F");
    al.add(1, "java2s.com");

    System.out.println("Size of al after additions: " + al.size());

    System.out.println("Contents of al: " + al);

    al.remove("F");
    al.remove(2);

    System.out.println("Size of al after deletions: " + al.size());
    System.out.println("Contents of al: " + al);
}

From source file:MainClass.java

public static void main(String args[]) {
    ArrayList<String> al = new ArrayList<String>();

    System.out.println("Initial size of al: " + al.size());

    al.add("C");
    al.add("A");/*from  w  w w .  ja v a 2 s .  c om*/
    al.add("E");
    al.add("B");
    al.add("D");
    al.add("F");
    al.add(1, "A2");

    System.out.println("Size of al after additions: " + al.size());

    System.out.println("Contents of al: " + al);

    al.remove("F");
    al.remove(2);

    System.out.println("Size of al after deletions: " + al.size());
    System.out.println("Contents of al: " + al);
}

From source file:CustomAuthenticationExample.java

public static void main(String[] args) {

    // register the auth scheme
    AuthPolicy.registerAuthScheme(SecretAuthScheme.NAME, SecretAuthScheme.class);

    // include the scheme in the AuthPolicy.AUTH_SCHEME_PRIORITY preference,
    // this can be done on a per-client or per-method basis but we'll do it
    // globally for this example
    HttpParams params = DefaultHttpParams.getDefaultParams();
    ArrayList schemes = new ArrayList();
    schemes.add(SecretAuthScheme.NAME);
    schemes.addAll((Collection) params.getParameter(AuthPolicy.AUTH_SCHEME_PRIORITY));
    params.setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, schemes);

    // now that our scheme has been registered we can execute methods against
    // servers that require "Secret" authentication... 
}

From source file:Main.java

public static void main(String[] args) {
    try {/*  w ww  . ja  va 2s.co m*/
        BufferedReader input = new BufferedReader(new FileReader(args[0]));
        ArrayList list = new ArrayList();
        String line;
        while ((line = input.readLine()) != null) {
            list.add(line);
        }
        input.close();

        Collections.reverse(list);

        PrintWriter output = new PrintWriter(new BufferedWriter(new FileWriter(args[1])));
        for (Iterator i = list.iterator(); i.hasNext();) {
            output.println((String) i.next());
        }
        output.close();
    } catch (IOException e) {
        System.err.println(e);
    }
}

From source file:com.example.AsyncClientHttpExchange.java

public static void main(String[] args) throws Exception {
    HttpAsyncClient httpclient = new DefaultHttpAsyncClient();
    httpclient.start();/*from  w ww .j  a  va 2  s  .c om*/
    try {

        ArrayList<Future<HttpResponse>> response = new ArrayList<Future<HttpResponse>>();

        ArrayList<String> sites = new ArrayList<String>();

        sites.add("MLA");
        sites.add("MLB");
        sites.add("MLU");
        sites.add("MLV");

        for (String site : sites) {
            HttpGet request = new HttpGet("https://api.mercadolibre.com/sites/" + site);
            Future<HttpResponse> r = httpclient.execute(request, null);
            response.add(r);
        }

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

        for (Future<HttpResponse> future : response) {
            HttpResponse r = future.get();
            System.out.println("Response: " + r.getStatusLine());
            System.out.println("Body : " + convertStreamToString(r.getEntity().getContent()));
        }

    } finally {
        httpclient.shutdown();
    }
    System.out.println("Done");
}

From source file:MLModelUsageSample.java

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

    MLModelUsageSample modelUsageSample = new MLModelUsageSample();

    // Path to downloaded-ml-model (downloaded-ml-model can be found inside resources folder)
    URL resource = MLModelUsageSample.class.getClassLoader().getResource("downloaded-ml-model");
    String pathToDownloadedModel = new File(resource.toURI()).getAbsolutePath();

    // Deserialize
    MLModel mlModel = modelUsageSample.deserializeMLModel(pathToDownloadedModel);

    // Predict/*from w w  w  .  j ava2  s.  c  o  m*/
    String[] featureValueArray1 = new String[] { "2", "84", "0", "0", "0", "0.0", "0.304", "21" };
    String[] featureValueArray2 = new String[] { "0", "101", "80", "40", "0", "26", "0.5", "33" };
    ArrayList<String[]> list = new ArrayList<String[]>();
    list.add(featureValueArray1);
    list.add(featureValueArray2);
    modelUsageSample.predict(list, mlModel);
}

From source file:fr.assoba.open.perf.GenDist.java

public static void main(String[] args) {
    // Magic number !
    LogNormalDistribution distribution = new LogNormalDistribution(6.73, 2.12);
    ArrayList<Long> list = new ArrayList<Long>();
    for (int i = 0; i < 1023; i++) {
        double d = (1.0 * i) / 1023.0;
        list.add((long) (100 * distribution.inverseCumulativeProbability(d)));
    }//from w ww.j  a va 2s. c  o  m
    System.out.print(Joiner.on(",").join(list));

}