Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我是 groovy 应用程序的新手。
我的数组是:def xyz = [{a:'a'},{b:'b'},{c:'c'}]
def xyz = [{a:'a'},{b:'b'},{c:'c'}]
我对 xyz 的预期输出应该是:[{x:'x'},{a:'a'},{b:'b'},{c:'c'}]
[{x:'x'},{a:'a'},{b:'b'},{c:'c'}]
鉴于您有:
def xyz = [[a:'a'],[b:'b'],[c:'c']]
然后你可以这样做:
xyz = [[x:'x']] + xyz
以便:
assert xyz == [[x:'x'], [a:'a'], [b:'b'], [c:'c']]
不完全是您的示例,但我可以在 groovyConsole 中运行它
def xyz = ['a','b','c'] xyz.add(0, 'x') println xyz
哪个打印
[x, a, b, c]