Skip to content

Instantly share code, notes, and snippets.

@erdi
Created November 7, 2011 16:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erdi/1345462 to your computer and use it in GitHub Desktop.
Save erdi/1345462 to your computer and use it in GitHub Desktop.
class A {
String value
}
def list = [new A(value: 'a'), new A(value: 'b'), new A(value: 'c'), new A(value: 'd')]
//we don't know the order and what is in list, we want to move object with value 'c' to the beggining of the list
def moved = list.find { it.value == 'c' }
list.remove(moved)
list.putAt(0, moved)
assert list.indexOf(moved) == 0
assert list.count(moved) == 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment