Java tutorial
//package com.java2s; //License from project: Apache License import java.util.ArrayList; import java.util.Collections; import java.util.List; public class Main { public static <T> List<T> readOnlyCopy(List<T> orig) { if (orig.isEmpty()) return Collections.emptyList(); if (orig.size() == 1) return Collections.singletonList(orig.get(0)); ArrayList<T> copy = new ArrayList<>(orig.size()); copy.addAll(orig); return Collections.unmodifiableList(copy); } }