public static void main(String[] args) {
List<Integer> list = new ArrayList<Integer>();
list.add(1);
list.add(2);
list.add(3);
list.add(4);
System.out.println(list);
int one = 0;
int two = 0;
for (int i = 0; i < list.size(); i++) {
int n = list.get(i);
if(5 == n){
if(i-1>=0){
one = list.get(i-1);
}
if(list.size() > i+1){
two = list.get(i+1);
}
}
}
System.out.println("上一个:"+one);
System.out.println("下一个:"+two);
}