Java tutorial
//package com.java2s; /** * jcombinatorics: * Java Combinatorics Library * * Copyright (c) 2009 by Alistair A. Israel. * * This software is made available under the terms of the MIT License. * See LICENSE.txt. * * Created Aug 31, 2009 */ import java.util.Arrays; public class Main { /** * @param elements * the elements to choose from * @param indices * the array of indices * @return the mapped array */ public static char[] valuesAt(final char[] elements, final int[] indices) { final int n = indices.length; final char[] result = new char[n]; for (int i = 0; i < n; ++i) { result[i] = elements[indices[i]]; } return result; } /** * @param elements * the elements to choose from * @param indices * the array of indices * @return the mapped array */ public static int[] valuesAt(final int[] elements, final int[] indices) { final int n = indices.length; final int[] result = new int[n]; for (int i = 0; i < n; ++i) { result[i] = elements[indices[i]]; } return result; } /** * @param <T> * a type * @param elements * the elements to choose from * @param indices * the array of indices * @return the mapped array */ public static <T> T[] valuesAt(final T[] elements, final int[] indices) { final int n = indices.length; final T[] result = Arrays.copyOf(elements, n); for (int i = 0; i < n; ++i) { result[i] = elements[indices[i]]; } return result; } }