由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Java版 - 关于对象向量删除/添加
相关主题
类里的字符串向量赋值,总报错:那个数组找duplicate的面试题
JAVA里什么METHOD是用来STRING PATTERN SEARCH折腾了一天,实在是绝望了,请教请教
知道一个key的value, 能不能O(1)从HashMap里拿出对应key和valueRe: Confused!
java http request能做到打开一次多次发送http request吗Re: strange exception
question about install jdbcList, LinkedList and Vector
how to get time(ms) in Java?关于Vector的土问题
Help: UnknownHostExceptionthanks Re: 关于Vector的土问题
non-GPL free/oss embeded object/xml database?Array of vector, help
相关话题的讨论汇总
话题: aaa话题: vector话题: ta话题: aaalist1话题: new
1 (共1页)
l***e
发帖数: 480
1
还有一个问题,关于对象向量删除/添加。
一个对象:
CLASS AAA{
STRING BBBB;
INT CCC;

VECTOR(AAA)AAALIST1=NEW VECTOR(AAA);
VECTOR(AAA)AAALIST2=NEW VECTOR(AAA);
AAA TA=NEW AAA();
FOR(AAA A1:AAALIST1){
IF(A1.CCC == ZZZZ)TA=A1;

AAALIST2.ADD(TA);
AAALIST1.REMOVE(TA);
当AAALIST1里只有一个元素时,总也删不掉最后一个。
还有这种对象向量中查找/删除有没有更简练的方法。
我这里用FOR遍历,感觉很累。
c*****t
发帖数: 1879
2
Seriously, paste real code and run a debugger...

【在 l***e 的大作中提到】
: 还有一个问题,关于对象向量删除/添加。
: 一个对象:
: CLASS AAA{
: STRING BBBB;
: INT CCC;
: }
: VECTOR(AAA)AAALIST1=NEW VECTOR(AAA);
: VECTOR(AAA)AAALIST2=NEW VECTOR(AAA);
: AAA TA=NEW AAA();
: FOR(AAA A1:AAALIST1){

l***e
发帖数: 480
3
我现在是加了一个判断,当只有一个时,取第一个,然后清空向量。
the problem is found by debugging.
sorry, real code is very messy.
CLASS AAA{
String BBBB;
int CCC;

Vector AAALIST1=new Vector
Vector AAALIST2=new Vector
AAA TA = new AAA();
For(AAA A1:AAALIST1){
if(A1.CCC == ZZZZ)TA=A1;

AAALIST2.add(TA);
AAALIST1.remove(TA);
A**o
发帖数: 1550
4
at least pay some respect to java coding standard, pls.
such as:
class Aaa
String bbbb;
etc
otherwise, it's really frustrating to read your psedo code

【在 l***e 的大作中提到】
: 我现在是加了一个判断,当只有一个时,取第一个,然后清空向量。
: the problem is found by debugging.
: sorry, real code is very messy.
: CLASS AAA{
: String BBBB;
: int CCC;
: }
: Vector AAALIST1=new Vector
: Vector AAALIST2=new Vector
: AAA TA = new AAA();

l***e
发帖数: 480
5
sorry about that.
I use a website to input Chinese. only capital letters are acceptable.
class Aaa{
String bbbb;
int ccc;

Vector AaaList1=new Vector
Vector AaaList2=new Vector
Aaa ta = new Aaa();
For(Aaa a1:AaaList1){
if(a1.ccc == zzzz)
ta = a1;

AaaList2.add(ta);
AaaList1.remove(ta);
g*****g
发帖数: 34805
6

Shouldn't these 2 lines in the loop?

【在 l***e 的大作中提到】
: sorry about that.
: I use a website to input Chinese. only capital letters are acceptable.
: class Aaa{
: String bbbb;
: int ccc;
: }
: Vector AaaList1=new Vector
: Vector AaaList2=new Vector
: Aaa ta = new Aaa();
: For(Aaa a1:AaaList1){

l***e
发帖数: 480
7
No,
The loop is for finding the right element to move from AaaList1 to AaaList2.
g*****g
发帖数: 34805
8
In that case, you should init the variable to null,
you should start from the end to start for better performance,
you should check if the element can be found.

AaaList2.

【在 l***e 的大作中提到】
: No,
: The loop is for finding the right element to move from AaaList1 to AaaList2.

l***e
发帖数: 480
9

which variable? ta?
do you mean I should use Iterator to loop?
The loop is to find the lowest one in the vector. so an element will be
found.
3x for your reply.

【在 g*****g 的大作中提到】
: In that case, you should init the variable to null,
: you should start from the end to start for better performance,
: you should check if the element can be found.
:
: AaaList2.

c*****t
发帖数: 1879
10
受不了你。你不会执行下 debugger ?再说你的逻辑很明显有问题,你的代码
没有任何地方表明是在找 lowest one in the vector 。早就说,你要贴就贴
真的代码。

【在 l***e 的大作中提到】
:
: which variable? ta?
: do you mean I should use Iterator to loop?
: The loop is to find the lowest one in the vector. so an element will be
: found.
: 3x for your reply.

g*****g
发帖数: 34805
11
his code is looking for an object equals to zzzz, how that becomes
the lowest one is beyond me. He's not getting it, we are not getting
it either.

【在 c*****t 的大作中提到】
: 受不了你。你不会执行下 debugger ?再说你的逻辑很明显有问题,你的代码
: 没有任何地方表明是在找 lowest one in the vector 。早就说,你要贴就贴
: 真的代码。

l***e
发帖数: 480
12
抱歉,我的伪代码有问题。
搞定了。
抱歉,误导。
w*****d
发帖数: 2415
13
Why not use ArrayList? Why not use indexOf method? Why not RTFM?

【在 l***e 的大作中提到】
: 还有一个问题,关于对象向量删除/添加。
: 一个对象:
: CLASS AAA{
: STRING BBBB;
: INT CCC;
: }
: VECTOR(AAA)AAALIST1=NEW VECTOR(AAA);
: VECTOR(AAA)AAALIST2=NEW VECTOR(AAA);
: AAA TA=NEW AAA();
: FOR(AAA A1:AAALIST1){

h*****0
发帖数: 4889
14
应该是new Vector(Aaa)();吧
再者你没做任何关于bbbb, ccc的初始化……

【在 l***e 的大作中提到】
: sorry about that.
: I use a website to input Chinese. only capital letters are acceptable.
: class Aaa{
: String bbbb;
: int ccc;
: }
: Vector AaaList1=new Vector
: Vector AaaList2=new Vector
: Aaa ta = new Aaa();
: For(Aaa a1:AaaList1){

1 (共1页)
相关主题
Array of vector, helpquestion about install jdbc
Re: Is there any way to uniquely identifhow to get time(ms) in Java?
a garbage collection questionHelp: UnknownHostException
请教java定义变量non-GPL free/oss embeded object/xml database?
类里的字符串向量赋值,总报错:那个数组找duplicate的面试题
JAVA里什么METHOD是用来STRING PATTERN SEARCH折腾了一天,实在是绝望了,请教请教
知道一个key的value, 能不能O(1)从HashMap里拿出对应key和valueRe: Confused!
java http request能做到打开一次多次发送http request吗Re: strange exception
相关话题的讨论汇总
话题: aaa话题: vector话题: ta话题: aaalist1话题: new