I am getting below Error with the below code. is there any alternate way to do this.
I am getting [I cannot be cast to java.lang.Integer] Error with the below code. is there any alternate way to do this.
package collectionTest;
import java.util.*;
public class ContinuesNumber {
public static void main(String[] args) {
int[] num = new int[]{3,5,81,6,3,789,67,56,79,8,76,80,6,77,7};
List<Integer> list = new ArrayList(Arrays.asList(num));
Set<Integer> count = new HashSet<Integer>();
Set<Integer> tmp = new HashSet<Integer>();
for(Integer i=0;i<list.size();i++)
{
int var = list.get(i);
int incr = var+1;
int decr = var-1;
tmp.add(list.get(i));
for(Integer j=i+1;j<list.size();j++)
{
if(incr==list.get(j) || decr==list.get(j))
{
tmp.add(list.get(j));
if(list.get(j)>list.get(i))
incr++;
else
decr--;
continue;
}
else
{
list.remove(list.get(j));
}
}
}
if(count.size()>tmp.size())
{
count.addAll(tmp);
}
System.out.println("most continuous elements are : "+ count);
}
}