Solved

Need Help to play arround with Collection Object

Posted on 2006-06-30
7
234 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
hibernate example issues from command prompt 10 85
collection output issue 9 91
web project error add remove 1 79
dao vs facade design patterns 2 69
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…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

734 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