I fixed an endless loop by changing Integer to int in the following:
public class IntTest { public static void main(String[] args) { Integer x=-1
Integer is a class wrapper around the Java primitive type int. They are not the same thing. you should be using int instead of Integer unless you have a valid reason (such as ArrayList list;
ArrayList list