Solved

Need Help to play arround with Collection Object

Posted on 2006-06-30
7
228 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Modeling a class in java 5 46
Running Jira on Raspberry PI 2? 3 251
Free Alternative to JIRA 4 91
split string containing \r\n in Java 46 38
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
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 video teaches viewers about errors in exception handling.

911 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