本文介绍了java.util.Vector的奇怪行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不确定我是否会生气或愚蠢但是我可以依赖我的眼睛上的
,当我将一个元素添加到Vector时,它会被放置

所有位置,而不是最后一个位置。这就好比如果它沿着列表的方向滚动所有

一直留下它的足迹。

我写的
,如:

import java.util。*;


public class Temp {

public static void main(String [] arg){

Vector vec = new Vector();

String [] outPutLine = new String [3];

String line;

for(int k = 0; k
for(int i = 0; i< outPutLine.length; i ++)

outPutLine [i ] =" S(" + i +" ;;" + k +")" ;;

vec.add(outPutLine);


System.out.println(" outPutLine" + k +" is:\t\t" + outPutLine [0] +

" \t" + outPutLine [ 1] +" \t" + outPutLine [2]);

System.out.println("结果是:");


String test ="" ;;

for(int i = 0; i< vec.size(); i ++){

for(int j = 0; j
test + =((String [])vec.get(i))[j];

test + =" \ n" ;;

}

System.out.println(test +" \\\
------------------------------ --- \ n");

}

}

}


所以,它只是我还是有输出的时髦?例如,

元素S(0; 0)去了哪里?!


-


请支付

Konrad

-------------------------------- -------------------

愿所有垃圾邮件发送者死于痛苦的死亡;没有埋葬地点;

他们的灵魂会被Gehenna的恶魔从一个房间追逐到

另一个永恒和更多。


睡眠 - 无效人士使用的东西

作为咖啡的替代品


野心 - 一个糟糕的借口没有

足够的感觉是懒惰的

------------------------------------- --------------

I''m not sure if i''m going mad or stupid but as far as i can rely
on my eyes, when i ADD an element to a Vector, it gets put on
ALL the position, instead of the last one. It''s like if it rolls all
the way down the list leaving its footprints along the way.

I wrote, like:
import java.util.*;

public class Temp {
public static void main (String[] arg) {
Vector vec = new Vector ();
String[] outPutLine = new String[3];
String line;
for (int k = 0; k < 4; k++) {
for (int i = 0; i < outPutLine.length; i++)
outPutLine[i] = "S(" + i + ";" + k + ")";
vec.add (outPutLine);

System.out.println ("outPutLine " + k + " is: \t\t" + outPutLine[0] +
"\t" + outPutLine[1] + "\t" + outPutLine[2]);
System.out.println ("The result is:");

String test = "";
for (int i = 0; i < vec.size (); i++) {
for (int j = 0; j < 3; j++)
test += ((String[])vec.get (i))[j];
test += "\n";
}
System.out.println (test + "\n---------------------------------\n");
}
}
}

So, is it just me or is there funky with the output? Where did the
element S(0;0) go, for instance?!

--

Kindly
Konrad
---------------------------------------------------
May all spammers die an agonizing death; have no burial places;
their souls be chased by demons in Gehenna from one room to
another for all eternity and more.

Sleep - thing used by ineffective people
as a substitute for coffee

Ambition - a poor excuse for not having
enough sense to be lazy
---------------------------------------------------


推荐答案








用S(0; 1)覆盖它。


建议:移动作业outPutLine = new String [3];"在

" for(int k ...)中环。这样你就可以创建四个String [3],

,如果你想存储12个单独的字符串,这很有用......


Mut ,


克里斯

-

Chris Gray

/ k /嵌入式Java解决方案



You overwrote it with S(0;1).

Suggestion: move the assignment "outPutLine = new String[3];" inside the
"for (int k ...)" loop. That way you will be creating four String[3]''s,
which is useful if you want to store 12 separate strings ...

Mut,

Chris
--
Chris Gray ch***@kiffer.eunet.be
/k/ Embedded Java Solutions


这篇关于java.util.Vector的奇怪行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-14 12:44