java vector如何放入string数组 不是遍历放入
展开全部
import java.util.Vector;
public class List10
{
public static void main(String[] args)
{
String[] str1= {"aaa","bbb"};
String[] str2= {"ccc","ddd","eee"};
Vector vec = new Vector();
//放入第一个数组
vec.add(str1);
//放入第二个数组
vec.add(str2);
//取出第一个数组将每一个输出 若取第二个数组,可用get(1)
String[] str3= (String[])vec.get(0);
for(String str:str3)
{
System.out.println(str);
}
}
}
public class List10
{
public static void main(String[] args)
{
String[] str1= {"aaa","bbb"};
String[] str2= {"ccc","ddd","eee"};
Vector vec = new Vector();
//放入第一个数组
vec.add(str1);
//放入第二个数组
vec.add(str2);
//取出第一个数组将每一个输出 若取第二个数组,可用get(1)
String[] str3= (String[])vec.get(0);
for(String str:str3)
{
System.out.println(str);
}
}
}
追问
错误提示:
The method add(String) in the type Vector is not applicable for the arguments (String[])
展开全部
public static void main(String[] args)
{
Vector<String> vector = new Vector<String>();
String[] a = new String[]{"a", "b", "c"};
String[] b = new String[]{"d", "e", "f"};
vector.addAll(Arrays.asList(a));
vector.addAll(Arrays.asList(b));
for (Iterator<String> iter = vector.iterator(); iter.hasNext();) {
String value = iter.next();
System.out.println(value);
}
}
{
Vector<String> vector = new Vector<String>();
String[] a = new String[]{"a", "b", "c"};
String[] b = new String[]{"d", "e", "f"};
vector.addAll(Arrays.asList(a));
vector.addAll(Arrays.asList(b));
for (Iterator<String> iter = vector.iterator(); iter.hasNext();) {
String value = iter.next();
System.out.println(value);
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询