I having a problem with coding this:
Write a static method named removeDuplicates that takes as input an array of integers and returns as a result a new
Maybe you can use lambdaj (download here,website), this library is very powerfull for managing collections (..list,arrays), the following code is very simple and works perfectly:
import static ch.lambdaj.Lambda.selectDistinct;
import java.util.Arrays;
import java.util.List;
public class DistinctList {
public static void main(String[] args) {
List numbers = Arrays.asList(1,3,4,2,1,5,6,8,8,3,4,5,13);
System.out.println("List with duplicates: " + numbers);
System.out.println("List without duplicates: " + selectDistinct(numbers));
}
}
This code shows:
List with duplicates: [1, 3, 4, 2, 1, 5, 6, 8, 8, 3, 4, 5, 13]
List without duplicates: [1, 2, 3, 4, 5, 6, 8, 13]
In one line you can get a distinct list, this is a simple example but with this library you can resolve more.
selectDistinct(numbers)
You must add lambdaj-2.4.jar to your project. I hope this will be useful.
Note: This will help you assuming you can have alternatives to your code.