6 Replies - 344 Views - Last Post: 03 April 2013 - 08:01 AM Rate Topic: -----

#1 tieugiang94  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 160
  • Joined: 07-December 11

clear() not remove elements in Vector

Posted 03 April 2013 - 03:23 AM

I use clear() method to clear all element in current Vector, then I assign new element to Vector.
But clear() method still keep old element.
In the picture below, 4 row is same data ( that's wrong )
Why is it ? Problems with resultSet ?
Attached Image

p/s: I don't want to create new vector, So i use clear() method to clear old element. Any suggest for this ?

This post has been edited by tieugiang94: 03 April 2013 - 03:25 AM


Is This A Good Question/Topic? 0
  • +

Replies To: clear() not remove elements in Vector

#2 GregBrannon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2198
  • View blog
  • Posts: 5,226
  • Joined: 10-September 10

Re: clear() not remove elements in Vector

Posted 03 April 2013 - 03:32 AM

Are you sure the code inside the while() loop is executing?
Was This Post Helpful? 0
  • +
  • -

#3 tieugiang94  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 160
  • Joined: 07-December 11

Re: clear() not remove elements in Vector

Posted 03 April 2013 - 03:44 AM

Oh, why not ? I printed the size, and it is 0. But datas are keeped.
Was This Post Helpful? 0
  • +
  • -

#4 pbl  Icon User is online

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8334
  • View blog
  • Posts: 31,858
  • Joined: 06-March 08

Re: clear() not remove elements in Vector

Posted 03 April 2013 - 03:48 AM

View Posttieugiang94, on 03 April 2013 - 06:44 AM, said:

Oh, why not ? I printed the size, and it is 0. But datas are keeped.

What do you mean is keeped ?
A Vector.clear() remove the elements from a Vector, it does not destroy them
If they are use somewhere else they will still be displayed somewhere else
Was This Post Helpful? 0
  • +
  • -

#5 tieugiang94  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 160
  • Joined: 07-December 11

Re: clear() not remove elements in Vector

Posted 03 April 2013 - 04:15 AM

I assign data from datbase to vector. In new loop I use clear() to clear the Vector ( make it empty then add new data from database ).

Problem is, Vector do not contain new datas from database in each Loop. Althought I clear() then add() again ? Why is it ?

This post has been edited by tieugiang94: 03 April 2013 - 04:15 AM

Was This Post Helpful? 0
  • +
  • -

#6 g00se  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2735
  • View blog
  • Posts: 11,520
  • Joined: 20-September 08

Re: clear() not remove elements in Vector

Posted 03 April 2013 - 05:59 AM

There are two issues here:

a. you're not clearing anything - you're adding to the data already in the model
b. you're doing that wrongly - each row must have a new Vector (which therefore must be created inside the loop and not before it)

This post has been edited by g00se: 03 April 2013 - 05:59 AM

Was This Post Helpful? 0
  • +
  • -

#7 tieugiang94  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 160
  • Joined: 07-December 11

Re: clear() not remove elements in Vector

Posted 03 April 2013 - 08:01 AM

View Postg00se, on 03 April 2013 - 05:59 AM, said:

There are two issues here:

a. you're not clearing anything - you're adding to the data already in the model
b. you're doing that wrongly - each row must have a new Vector (which therefore must be created inside the loop and not before it)


Oh, I found the problem. Thannk you :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1