简体   繁体   中英

Why Groovy Pop() function is removing the first element from list?

I'm new to Groovy. I was trying Pop function, which should remove last element from the list acc to documentation. But it pops the first element in my case instead of last. Can any one tell me if that's a bug or am I missing something here?

This is the list i'm using:

def primes = [25,3,5,7,11,13];

Here is the output screenshot:

ss

https://docs.groovy-lang.org/latest/html/groovy-jdk/java/util/List.html#pop()

Removes the initial item from the List.

def list = ["a", false, 2]
assert list.pop() == 'a'
assert list == [false, 2]

This is similar to pop on a Stack where the first item in the list represents the top of the stack. Note: The behavior of this method changed in Groovy 2.5 to align with Java. If you need the old behavior use 'removeLast'.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM