# Code to find Permutation of Numbers

## Introduction

The article is about writing a Code to find permutation of numbers, the program prints all possible permutations of a given list or array of numbers. I have this question listed on my Stackoverflow.com account as well. To know the opinions of other people on the same and to find out other ways to solve the problem, please visit the link Also, you might be interested in the code for Combinations. Find it here

## Problem Statement

Given a list of numbers, print the possible permutations. The program must also be able to print P(n,r) where N and r can be input parameters. Before writing the code it would be better to have a clear understanding of what permutation means. P(n.r) means given n items choose r at a time and list all possible combination of r items from the set of n items. For e.g. if there are three numbers 1, 2 and 3 then P(3,2) would result into : P(3,2) : Count (6) :- [[3, 1], [2, 1], [3, 2], [1, 3], [2, 3], [1, 2]]

## Code and Implementation

Below is the java code to find permutation of numbers
```package com.algorithm;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class Permutations {
public static void main(String args[]) {
Permutations obj = new Permutations();
Collection input = new ArrayList();

Collection<List> output = obj.permute(input);
int k = 0;
Set<List> pnr = null;
for (int i = 0; i <= input.size(); i++) {
pnr = new HashSet<List>();
for(List integers : output){
}
k = input.size()- i;
System.out.println("P("+input.size()+","+k+") :"+
"Count ("+pnr.size()+") :- "+pnr);
}
}
public Collection<List> permute(Collection input) {
Collection<List> output = new ArrayList<List>();
if (input.isEmpty()) {
return output;
}
List list = new ArrayList(input);
List rest = list.subList(1, list.size());
for (List permutations : permute(rest)) {
List<List> subLists = new ArrayList<List>();
for (int i = 0; i <= permutations.size(); i++) {
List subList = new ArrayList();