List of usage examples for java.util List toArray
Object[] toArray();
From source file:Main.java
public static void main(String[] args) { List<String> list = new ArrayList<String>(); list.add("A"); list.add("B"); list.add("C"); list.add("D"); Object[] array = list.toArray(); for (int i = 0; i < array.length; i++) { System.out.println(array[i].toString()); }//ww w .j a va 2 s. c om }
From source file:Main.java
public static void main(String[] args) { List<String> list = new ArrayList<>(); for (int i = 0; i < 30; i++) { list.add("Hello, World " + i); }/*www . j a v a 2 s . c o m*/ JScrollPane pane = new JScrollPane(new JList(list.toArray())) { @Override public Dimension getPreferredSize() { return new Dimension(200, 250); } }; JOptionPane.showMessageDialog(null, pane); }
From source file:Main.java
public static void main(String[] args) throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true);// www . ja v a 2 s . co m DocumentBuilder builder; Document doc = null; builder = factory.newDocumentBuilder(); doc = builder.parse("employees.xml"); // Create XPathFactory object XPathFactory xpathFactory = XPathFactory.newInstance(); // Create XPath object XPath xpath = xpathFactory.newXPath(); String name = getEmployeeNameById(doc, xpath, 4); System.out.println("Employee Name with ID 4: " + name); List<String> names = getEmployeeNameWithAge(doc, xpath, 30); System.out.println("Employees with 'age>30' are:" + Arrays.toString(names.toArray())); List<String> femaleEmps = getFemaleEmployeesName(doc, xpath); System.out.println("Female Employees names are:" + Arrays.toString(femaleEmps.toArray())); }
From source file:Main.java
public static void main(String[] args) { // create array list object List<Integer> numbers = new ArrayList<Integer>(); // populate the list for (int i = 0; i < 15; i++) { numbers.add(i);/*w ww . j ava2s . c om*/ } System.out.println("Before : " + Arrays.toString(numbers.toArray())); // rotate the list at distance 10 Collections.rotate(numbers, 10); System.out.println("After : " + Arrays.toString(numbers.toArray())); }
From source file:Main.java
public static void main(String[] argv) throws Exception { DefaultTableModel model = new DefaultTableModel(); JTable table = new JTable(model); model.addColumn("Col1"); model.addRow(new Object[] { "r1" }); model.addRow(new Object[] { "r2" }); model.addRow(new Object[] { "r3" }); Vector data = model.getDataVector(); Vector row = (Vector) data.elementAt(1); int mColIndex = 0; List colData = new ArrayList(table.getRowCount()); for (int i = 0; i < table.getRowCount(); i++) { row = (Vector) data.elementAt(i); colData.add(row.get(mColIndex)); }/*from w w w .jav a 2 s .c om*/ // Append a new column with copied data model.addColumn("Col3", colData.toArray()); JFrame f = new JFrame(); f.setSize(300, 300); f.add(new JScrollPane(table)); f.setVisible(true); }
From source file:ToArray.java
public static void main(String[] args) { List list = new ArrayList(); list.add("Blobbo"); list.add("Cracked"); list.add("Dumbo"); // list.add(new Date()); // Don't mix and match! // Convert a collection to Object[], which can store objects // of any type. Object[] ol = list.toArray(); System.out.println("Array of Object has length " + ol.length); // This would throw an ArrayStoreException if the line // "list.add(new Date())" above were uncommented. String[] sl = (String[]) list.toArray(new String[0]); System.out.println("Array of String has length " + sl.length); }
From source file:Main.java
public static void main(String[] args) { List<String> colours = new ArrayList<String>(); colours.add("red"); colours.add("green"); colours.add("blue"); colours.add("yellow"); colours.add("cyan"); colours.add("white"); colours.add("black"); Collections.sort(colours);//from ww w .j a v a 2 s . c o m System.out.println(Arrays.toString(colours.toArray())); Collections.sort(colours, Collections.reverseOrder()); System.out.println(Arrays.toString(colours.toArray())); }
From source file:org.mitre.mpf.rest.client.Main.java
public static void main(String[] args) throws RestClientException, IOException, InterruptedException { System.out.println("Starting rest-client!"); //not necessary for localhost, but left if a proxy configuration is needed //System.setProperty("http.proxyHost",""); //System.setProperty("http.proxyPort",""); String currentDirectory;//from w w w . j a va 2 s. c o m currentDirectory = System.getProperty("user.dir"); System.out.println("Current working directory : " + currentDirectory); String username = "mpf"; String password = "mpf123"; byte[] encodedBytes = Base64.encodeBase64((username + ":" + password).getBytes()); String base64 = new String(encodedBytes); System.out.println("encodedBytes " + base64); final String mpfAuth = "Basic " + base64; RequestInterceptor authorize = new RequestInterceptor() { @Override public void intercept(HttpRequestBase request) { request.addHeader("Authorization", mpfAuth /*credentials*/); } }; //RestClient client = RestClient.builder().requestInterceptor(authorize).build(); CustomRestClient client = (CustomRestClient) CustomRestClient.builder() .restClientClass(CustomRestClient.class).requestInterceptor(authorize).build(); //getAvailableWorkPipelineNames String url = "http://localhost:8080/workflow-manager/rest/pipelines"; Map<String, String> params = new HashMap<String, String>(); List<String> availableWorkPipelines = client.get(url, params, new TypeReference<List<String>>() { }); System.out.println("availableWorkPipelines size: " + availableWorkPipelines.size()); System.out.println(Arrays.toString(availableWorkPipelines.toArray())); //processMedia JobCreationRequest jobCreationRequest = new JobCreationRequest(); URI uri = Paths.get(currentDirectory, "/trunk/workflow-manager/src/test/resources/samples/meds/aa/S001-01-t10_01.jpg").toUri(); jobCreationRequest.getMedia().add(new JobCreationMediaData(uri.toString())); uri = Paths.get(currentDirectory, "/trunk/workflow-manager/src/test/resources/samples/meds/aa/S008-01-t10_01.jpg").toUri(); jobCreationRequest.getMedia().add(new JobCreationMediaData(uri.toString())); jobCreationRequest.setExternalId("external id"); //get first DLIB pipeline String firstDlibPipeline = availableWorkPipelines.stream() //.peek(pipepline -> System.out.println("will filter - " + pipepline)) .filter(pipepline -> pipepline.startsWith("DLIB")).findFirst().get(); System.out.println("found firstDlibPipeline: " + firstDlibPipeline); jobCreationRequest.setPipelineName(firstDlibPipeline); //grabbed from 'rest/pipelines' - see #1 //two optional params jobCreationRequest.setBuildOutput(true); //jobCreationRequest.setPriority(priority); //will be set to 4 (default) if not set JobCreationResponse jobCreationResponse = client.customPostObject( "http://localhost:8080/workflow-manager/rest/jobs", jobCreationRequest, JobCreationResponse.class); System.out.println("jobCreationResponse job id: " + jobCreationResponse.getJobId()); System.out.println("\n---Sleeping for 10 seconds to let the job process---\n"); Thread.sleep(10000); //getJobStatus url = "http://localhost:8080/workflow-manager/rest/jobs"; // /status"; params = new HashMap<String, String>(); //OPTIONAL //params.put("v", "") - no versioning currently implemented //id is now a path var - if not set, all job info will returned url = url + "/" + Long.toString(jobCreationResponse.getJobId()); SingleJobInfo jobInfo = client.get(url, params, SingleJobInfo.class); System.out.println("jobInfo id: " + jobInfo.getJobId()); //getSerializedOutput String jobIdToGetOutputStr = Long.toString(jobCreationResponse.getJobId()); url = "http://localhost:8080/workflow-manager/rest/jobs/" + jobIdToGetOutputStr + "/output/detection"; params = new HashMap<String, String>(); //REQUIRED - job id is now a path var and required for this endpoint String serializedOutput = client.getAsString(url, params); System.out.println("serializedOutput: " + serializedOutput); }
From source file:org.sbq.batch.mains.ActivityEmulator.java
public static void main(String[] vars) throws IOException { System.out.println("ActivityEmulator - STARTED."); ActivityEmulator activityEmulator = new ActivityEmulator(); activityEmulator.begin();//from ww w. j av a 2s.c om System.out.println("Enter your command: >"); BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String command = null; while (!"stop".equals(command = in.readLine())) { if ("status".equals(command)) { List<String> onlineUsers = new LinkedList<String>(); for (Map.Entry<String, AtomicBoolean> entry : activityEmulator.getUserStatusByLogin().entrySet()) { if (entry.getValue().get()) { onlineUsers.add(entry.getKey()); } } System.out.println("Users online: " + Arrays.toString(onlineUsers.toArray())); System.out.println("Number of cycles left: " + activityEmulator.getBlockingQueue().size()); } System.out.println("Enter your command: >"); } activityEmulator.stop(); System.out.println("ActivityEmulator - STOPPED."); }
From source file:ca.on.oicr.pde.deciders.GenomicAlignmentNovoalignDecider.java
public static void main(String args[]) { List<String> params = new ArrayList<String>(); params.add("--plugin"); params.add(GenomicAlignmentNovoalignDecider.class.getCanonicalName()); params.add("--"); params.addAll(Arrays.asList(args)); System.out.println("Parameters: " + Arrays.deepToString(params.toArray())); net.sourceforge.seqware.pipeline.runner.PluginRunner.main(params.toArray(new String[params.size()])); }