Solved

Need Help to play arround with Collection Object

Posted on 2006-06-30
7
233 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Spring Framework HTTPSession management 1 45
session migration servlets 2 42
login form jsp example 2 38
eclipse console opening separately 2 29
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

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