添加到 ArrayList Java [英] Adding to an ArrayList Java

查看:24
本文介绍了添加到 ArrayList Java的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Java 初学者,需要一些帮助.

I am a beginner to java, and need some help.

我正在尝试将关联列表的抽象数据类型 Foo 转换为字符串 B 的 Arraylist.如何遍历列表并将每个字符串添加到数组中.

I am trying to convert an Abstract Data type Foo which is an associated list to an Arraylist of the strings B. How do you loop through the list and add each string to the array.

我可能想多了,但我现在迷路了.

I may be over thinking it, but I am lost now.

提前感谢您的帮助.

推荐答案

实例化一个新的 ArrayList:

Instantiate a new ArrayList:

List<String> myList = new ArrayList<String>();

迭代您的数据结构(例如,使用 for 循环,有关您的代码的更多详细信息会有所帮助.)和每个元素 (yourElement):

Iterate over your data structure (with a for loop, for instance, more details on your code would help.) and for each element (yourElement):

myList.add(yourElement);

这篇关于添加到 ArrayList Java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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