List<String> list = new ArrayList<String>(); //add some stuff list.add("android"); list.add("apple"); String[] stringArray = list.toArray(new String[0]);
List<String> strings = new ArrayList<String>() strings.add("lol"); strings.add("cat"); Collections.sort(strings); for (String s : strings) { System.out.println(s); } // Prints out "cat" and "lol"
@Test public void startWithIterable() { List<String> li = new ArrayList<String>(); li.add("alpha"); li.add("beta"); List<String> values = Observable.just("one", "two").startWith(li).toList().blockingGet(); assertEquals("alpha", values.get(0)); assertEquals("beta", values.get(1)); assertEquals("one", values.get(2)); assertEquals("two", values.get(3)); }
public RenderOnDemandClosure(JellyContext context, String attributesToCapture) { List<Script> bodyStack = new ArrayList<Script>(); for (JellyContext c = context; c!=null; c=c.getParent()) { Script script = (Script) c.getVariables().get("org.apache.commons.jelly.body"); if(script!=null) bodyStack.add(script); } this.bodyStack = bodyStack.toArray(new Script[bodyStack.size()]); assert !bodyStack.isEmpty(); // there must be at least one, which is the direct child of <l:renderOnDemand> Map<String,Object> variables = new HashMap<String, Object>(); for (String v : Util.fixNull(attributesToCapture).split(",")) variables.put(v.intern(),context.getVariable(v)); // capture the current base of context for descriptors currentDescriptorByNameUrl = Descriptor.getCurrentDescriptorByNameUrl(); this.variables = PackedMap.of(variables); Set<String> _adjuncts = AdjunctsInPage.get().getIncluded(); this.adjuncts = new String[_adjuncts.size()]; int i = 0; for (String adjunct : _adjuncts) { this.adjuncts[i++] = adjunct.intern(); } }
@Override public ResponseSpec onStatus(Predicate<HttpStatus> statusPredicate, Function<ClientResponse, Mono<? extends Throwable>> exceptionFunction) { if (this.statusHandlers.size() == 1 && this.statusHandlers.get(0) == DEFAULT_STATUS_HANDLER) { this.statusHandlers.clear(); } this.statusHandlers.add(new StatusHandler(statusPredicate, (clientResponse, request) -> exceptionFunction.apply(clientResponse))); return this; }
@Override public V put(K key, V value) { list.remove(key); V v; if (maxSize > 0 && list.size() == maxSize) { //remove first K k = list.get(0); list.remove(0); v = map.remove(k); } else { v = null; } list.add(key); V result = map.put(key, value); if (v != null) { try { evictedListener.accept(v); } catch (Exception e) { throw new RuntimeException(e); } } return result; }
/** * Removes a path segment. When this method returns the last segment is always "", which means * the encoded path will have a trailing '/'. * * <p>Popping "/a/b/c/" yields "/a/b/". In this case the list of path segments goes from ["a", * "b", "c", ""] to ["a", "b", ""]. * * <p>Popping "/a/b/c" also yields "/a/b/". The list of path segments goes from ["a", "b", "c"] * to ["a", "b", ""]. */ private void pop() { String removed = encodedPathSegments.remove(encodedPathSegments.size() - 1); // Make sure the path ends with a '/' by either adding an empty string or clearing a segment. if (removed.isEmpty() && !encodedPathSegments.isEmpty()) { encodedPathSegments.set(encodedPathSegments.size() - 1, ""); } else { encodedPathSegments.add(""); } }
@Test public void testGenericTypeNestingListOfMapOfInteger() throws Exception { List<Map<String, String>> list = new LinkedList<>(); Map<String, String> map = new HashMap<>(); map.put("testKey", "5"); list.add(map); NestedGenericCollectionBean gb = new NestedGenericCollectionBean(); BeanWrapper bw = new BeanWrapperImpl(gb); bw.setPropertyValue("listOfMapOfInteger", list); Object obj = gb.getListOfMapOfInteger().get(0).get("testKey"); assertTrue(obj instanceof Integer); assertEquals(5, ((Integer) obj).intValue()); }
@Test public void testGenericListOfMaps() throws MalformedURLException { GenericBean<String> gb = new GenericBean<>(); List<Map<Integer, Long>> list = new LinkedList<>(); list.add(new HashMap<>()); gb.setListOfMaps(list); BeanWrapper bw = new BeanWrapperImpl(gb); bw.setPropertyValue("listOfMaps[0][10]", new Long(5)); assertEquals(new Long(5), bw.getPropertyValue("listOfMaps[0][10]")); assertEquals(new Long(5), gb.getListOfMaps().get(0).get(10)); }
/** Regression test for bug found. */ public void testCorrectOrdering_regression() { MinMaxPriorityQueue<Integer> q = MinMaxPriorityQueue.create(ImmutableList.of(3, 5, 1, 4, 7)); List<Integer> expected = ImmutableList.of(1, 3, 4, 5, 7); List<Integer> actual = new ArrayList<>(5); for (int i = 0; i < expected.size(); i++) { actual.add(q.pollFirst()); } assertEquals(expected, actual); }
protected HandshakeInterceptor[] getInterceptors() { List<HandshakeInterceptor> interceptors = new ArrayList<>(this.interceptors.size() + 1); interceptors.addAll(this.interceptors); interceptors.add(new OriginHandshakeInterceptor(this.allowedOrigins)); return interceptors.toArray(new HandshakeInterceptor[0]); }
class Test2 { public static void main(String[] s) { long st = System.currentTimeMillis(); List<String> l0 = new ArrayList<String>(); l0.add("Hello"); l0.add("World!"); List<String> l1 = new ArrayList<String>(); l1.add("Hello"); l1.add("World!"); /* snip */ List<String> l999 = new ArrayList<String>(); l999.add("Hello"); l999.add("World!"); System.out.println(System.currentTimeMillis() - st); } }