如何在Kotlin中使用堆栈? [英] How can I use stack in Kotlin?

查看:1301
本文介绍了如何在Kotlin中使用堆栈?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Kotlin中使用Stack(来自Java)?

How can I use Stack (from java) in Kotlin?

还有其他选择吗?

  • 我正在尝试将列表转换为Stack

谢谢

推荐答案

此操作与Java中的操作相同,但是使用Kotlin语法-val关键字与缺少new关键字的地方明显不同.例如:

This is done in the same way as you would in Java, but with Kotlin syntax - notably different are the val keyword and lack of new keyword. For example:

import java.util.Stack
...
val someList = ArrayList()
...
val stack = Stack()
stack.addAll(someList)

这篇关于如何在Kotlin中使用堆栈?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆