Solved

Need Help to play arround with Collection Object

Posted on 2006-06-30
7
230 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Cipher Configuration on Apache HTTPD 4 63
how to add new optional parameter to JSP 1 42
reverse digits of a number using for loop 5 45
MySQL  on Tomcat 8 47
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

821 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