Here you can find the source of reversed(List
Parameter | Description |
---|---|
T | The type of the items in the list |
l | The list to reverse |
public static <T> List<T> reversed(List<T> l)
//package com.java2s; /*/*w w w .ja v a 2s . c o m*/ * Copyright 2008-2009 LinkedIn, Inc * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. */ import java.util.ArrayList; import java.util.Collections; import java.util.List; public class Main { /** * A reversed copy of the given list * * @param <T> The type of the items in the list * @param l The list to reverse * @return The list, reversed */ public static <T> List<T> reversed(List<T> l) { List<T> copy = new ArrayList<T>(l); Collections.reverse(copy); return copy; } }