Solved

Need Help to play arround with Collection Object

Posted on 2006-06-30
7
226 Views
Last Modified: 2012-05-05

MenuMap menuMap= new MenuMap();
menuMap.setDisplayName(dispName);
menuMap.setURLString(urlPage);
menuMap.setPNG(iconImage);
menuMap.setDeficonText(deficonText);
MenuMapColl.add(menuMap);

######MenuMapColl is the collection and at later stage i am getting it size.

Menu Collection.size==12
then

I needto insert 4 things between each 3.

i will read first 3 from collection and insert 4 records from text file.

again read next 3 from collection and insert 4 records from text file ..until collection becomes zero



I need a piece of code for above
Thanks
0
Comment
Question by:cutie_smily
  • 4
  • 3
7 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 17018454
MenuMap is not an API class - is it your own?

If it's based on Map, then Map has no concept (normally) of 'between' - the collection is unordered
0
 

Author Comment

by:cutie_smily
ID: 17018588
Sorry! those are the variable names i used

###  MenuMap is my own info class where it get values from database and stores (get and set methods). The above one is setting values.

##  and MenuMapColl is a vector. Sorry I said it a collection obj

Vector MenuMapColl          = new Vector();  

MenuMap menuMap= new MenuMap();
menuMap.setDisplayName(dispName);
menuMap.setURLString(urlPage);
menuMap.setPNG(iconImage);
menuMap.setDeficonText(deficonText);
MenuMapColl.add(menuMap);

int size=MenuMapColl.size();
int reminder= size % 3;
0
 

Author Comment

by:cutie_smily
ID: 17018709
After 3 elements of the vector i need to read 4 elements from a file and insert in between vector and so on
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 86

Accepted Solution

by:
CEHJ earned 250 total points
ID: 17018729
You need something like


Vector newColl = new Vector();
for(int index = 0;index < MenuMapColl.size();i++) {
      Object current = MenuMapColl.get(index);
      if (index % 3 == 0 && index > 0) {
            insertFromTextFile(newColl); // You design this method
      }
      else {
            newColl.add(current);
      }  
}
// Now use 'newColl'
0
 

Author Comment

by:cutie_smily
ID: 17018970


That's what i wanted. Thankyou

0
 
LVL 86

Expert Comment

by:CEHJ
ID: 17019013
No problem
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 17019331
:-)
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now