List of usage examples for java.util List add
boolean add(E e);
From source file:Main.java
public static void main(String[] args) throws FileNotFoundException { List<Integer> arraySource = new ArrayList<>(); for (int i = 0; i < 99999; i++) { arraySource.add(i); }// w ww.ja v a2 s. c o m Integer[] myArray = new Integer[999]; myArray = arraySource.toArray(myArray); long startTime = System.currentTimeMillis(); Arrays.sort(myArray); long endTime = System.currentTimeMillis(); System.out.println("Time take in serial: " + (endTime - startTime) / 1000.0); Integer[] myArray2 = new Integer[999]; myArray2 = arraySource.toArray(myArray); startTime = System.currentTimeMillis(); Arrays.parallelSort(myArray2); endTime = System.currentTimeMillis(); System.out.println("Time take in parallel: " + (endTime - startTime) / 1000.0); }
From source file:Main.java
public static void main(String[] args) { Person p = new Person("A"); Animal a = new Animal("B"); Thing t = new Thing("C"); String text = "hello"; Integer number = 1000;// w w w. j a va 2s . c o m List<Object> list = new ArrayList<Object>(); list.add(p); list.add(a); list.add(t); list.add(text); list.add(number); for (int i = 0; i < list.size(); i++) { Object o = list.get(i); if (o instanceof Person) { System.out.println("My name is " + ((Person) o).getName()); } else if (o instanceof Animal) { System.out.println("I live in " + ((Animal) o).getHabitat()); } else if (o instanceof Thing) { System.out.println("My color is " + ((Thing) o).getColor()); } else if (o instanceof String) { System.out.println("My text is " + o.toString()); } else if (o instanceof Integer) { System.out.println("My value is " + ((Integer) o)); } } }
From source file:MainClass.java
public static void main(String args[]) throws Exception { SSLSocketFactory factory = HttpsURLConnection.getDefaultSSLSocketFactory(); SSLSocket socket = (SSLSocket) factory.createSocket("127.0.0.1", 9999); socket.startHandshake();//from w w w . j a va 2s . com SSLSession session = socket.getSession(); java.security.cert.Certificate[] servercerts = session.getPeerCertificates(); List mylist = new ArrayList(); for (int i = 0; i < servercerts.length; i++) { mylist.add(servercerts[i]); } CertificateFactory cf = CertificateFactory.getInstance("X.509"); CertPath cp = cf.generateCertPath(mylist); FileOutputStream f = new FileOutputStream("CertPath.dat"); ObjectOutputStream b = new ObjectOutputStream(f); b.writeObject(cp); }
From source file:Main.java
public static void main(String[] args) { List<String> l1 = new ArrayList<String>(); List<String> l2 = new ArrayList<String>(); l1.add("a"); l1.add("b");//from ww w . j a v a 2s . co m l1.add("c"); l2.add("b"); l2.add("c"); l2.add("a"); if (isSorted(l1)) { System.out.println("already sorted"); } else { Collections.sort(l1); } }
From source file:Main.java
public static void main(String[] args) { List<String> aList = new ArrayList<String>(); Map<Integer, String> aMap = new HashMap<Integer, String>(); aList.add("A"); aList.add("B"); for (int i = 0; i < aList.size(); i++) { aMap.put(i + 1, aList.get(i));// w ww .j av a 2s . co m } System.out.println(aMap.toString()); }
From source file:Main.java
public static void main(String[] args) throws InterruptedException { executors = new ForkJoinPool(); List<Long> sequence = new ArrayList<>(); for (int i = 0; i < 20; i++) { sequence.add(fib(i)); }/*from www .j a v a2 s. c om*/ System.out.println(sequence); }
From source file:com.fengduo.bee.commons.util.HttpClientUtils.java
public static void main(String[] args) throws Exception { String url = "https://api.submail.cn/message/xsend.json"; List<NameValuePair> list = new ArrayList<NameValuePair>(); list.add(new BasicNameValuePair("appid", "10245")); list.add(new BasicNameValuePair("to", "13771073096")); list.add(new BasicNameValuePair("project", "44g4a4")); list.add(new BasicNameValuePair("signature", "db81f10a40953015f9e8fa1a16017e4a")); list.add(new BasicNameValuePair("vars", "{\"checkCode\":\"410037\"}")); String result = HttpClientUtils.postRequest(url, list); System.out.println("------result----:" + result); }
From source file:com.sm.replica.TestRClient.java
public static void main(String[] args) { int i = 10;//from w w w. j a v a 2s. c o m List<String> list = new ArrayList<String>(i); for (int j = 0; j < i; j++) list.add(null); logger.info("freq " + list.size()); String logPath = "/Users/mhsieh/java/open/voldemort-0.81/config/addon-1/data/log"; String store = "test"; CacheStore trxLog = new CacheStore(logPath, null, 0, store, false); ReplicaClient client = new NTReplicaClient("localhost:6910", store, trxLog, logPath); new Thread(client).start(); }
From source file:com.sm.store.TestHessianPhp.java
public static void main(String[] args) throws Exception { HessianSerializer hs = new HessianSerializer(); // Map<String, String> map = new HashMap<String, String>(); // map.put("Header", "com.sm.message.Header"); // map.put("StoreParas", "com.sm.store.StoreParas"); // map.put("Value","com.sm.store.Value"); // map.put("array", "java.util.HashMap"); HessianPhp hessianPhp = new HessianPhp(getNameMap()); Map<String, Header> mapH = new HashMap<String, Header>(); mapH.put("key-1", new Header("test-1", 1, (byte) 2, 3)); mapH.put("key-2", new Header("test-2", 2, (byte) 3, 4)); // byte[] m1 = hs.toBytes( mapH); // System.out.println("m1 "+m1.length); // Header hd = new Header("test-1", 2, (byte)1, 3); // byte[] d2 = hs.toBytes( hd); // HessianReader reader = new HessianReader( m1); // reader.readObject(); // System.out.println(new String( reader.getBytes())); List list = new ArrayList(); list.add(new Header("test-1", 1, (byte) 2, 3)); list.add(new Header("test-2", 2, (byte) 3, 4)); byte[] d3 = hs.toBytes(list); HessianReader reader = new HessianReader(d3); reader.readObject();// w w w . ja va 2s . co m System.out.println(new String(reader.getBytes())); // byte[] data = hessianPhp.php2Hessian( header.getBytes()); // Header header = new Header("test-1",10, (byte) 3,1 ); // byte[] d1 = hs.toBytes( header); //logger.info("len "+data.length+" "+d1.length); //Object obj = hs.toObject(data); //logger.info(obj.getClass().getName()+" obj "+obj.toString()); // byte[] s1 = hessianPhp.php2Hessian( storePara.getBytes()); // Object obj = hs.toObject( s1); // logger.info(obj.toString()); }
From source file:Main.java
public static void main(String[] args) { List<Person> persons = new ArrayList<Person>(); persons.add(new Person("Peter", 65, Person.Gender.MALE)); persons.add(new Person("Kevin", 5, Person.Gender.MALE)); persons.add(new Person("Mandy", 19, Person.Gender.FEMALE)); // Method Reference Collection<Person> eighteen = list(persons, (Person p) -> p.getAge() >= 18); System.out.println(eighteen); // Method Reference static Collection<Person> malePersons = list(persons, Person::isMale); System.out.println(malePersons); // Method Reference non static Person a = new Person("a", 1, Person.Gender.MALE); Collection<Person> femalePersons = list(persons, a::isFemale); System.out.println(femalePersons); }