我正在尝试创建一个固定大小的集合,因此它只打印部分arraylist [英] I am trying to create a collection with a fixed size so it only prints part of the arraylist
本文介绍了我正在尝试创建一个固定大小的集合,因此它只打印部分arraylist的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
public static void main(String[]args){
String s = "Fee Fie Foe Fie";
String[] str = s.split(" ");
Collection<String> coll = new ArrayList<String>();
for (String t : str) {
coll.add(t);
}
System.out.print(coll);
}
我想要输出费用Fie Foe我该怎么做?
我尝试了什么:
我尝试将ArrayList设置为固定大小但是没有运气
I am trying to get the output Fee Fie Foe how do I do this?
What I have tried:
I have tried setting the ArrayList to a fixed size but with no luck
推荐答案
我们称之为数组
:
We call itarray
:
public static void main( String arg[])
{
final int SIZE = 3;
String s = "Fee Fie Foe Fie";
String[] str = s.split(" ");
String[] myArray = new String[SIZE];
for (int n=0; n<SIZE; ++n)
myArray[n] = str[n];
for (String a : myArray)
System.out.printf("%s ", a);
System.out.println();
}
这篇关于我正在尝试创建一个固定大小的集合,因此它只打印部分arraylist的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文