[color=red]队列:先进先出的容器[/color]
LinkedList 提供了方法支持队列行为,并且实现了Queue接口,可以向上转型为Queue。
[color=red]offer()[/color]方法是Queue的相关方法之一,在允许情况下,将一个元素插入到对尾,或者返回false。
[color=red]peek()和element()[/color]都将在不移除的情况下返回对头,peek在队列为空时返回null,而element会抛出NoSuchElementException异常。[color=red]poll()和remove()[/color]方法将移除并返回对头,但是poll()在队列为空时返回null,remove()返回NoSunchElementException异常。
自动包装机制会自动将nextInt()方法的int结构转换成queue需要的Integer对象,char转换成Character对象。
LinkedList 提供了方法支持队列行为,并且实现了Queue接口,可以向上转型为Queue。
[color=red]offer()[/color]方法是Queue的相关方法之一,在允许情况下,将一个元素插入到对尾,或者返回false。
[color=red]peek()和element()[/color]都将在不移除的情况下返回对头,peek在队列为空时返回null,而element会抛出NoSuchElementException异常。[color=red]poll()和remove()[/color]方法将移除并返回对头,但是poll()在队列为空时返回null,remove()返回NoSunchElementException异常。
自动包装机制会自动将nextInt()方法的int结构转换成queue需要的Integer对象,char转换成Character对象。