473,387 Members | 3,750 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Using vector

Expand|Select|Wrap|Line Numbers
  1. Vector v = new Vector();
  2. v=ctx.getAdminrole().getAttributeMultivalue();
  3.  
Now in the above code I am getting a set of strings in the object v.
Now i want to use the strings one by one for comparison.
So what type of code or loop i have to use to fetch the values stored in vector.

Any pointers in this regard will be very helpful
May 27 '08 #1
3 2208
JosAH
11,448 Expert 8TB
Expand|Select|Wrap|Line Numbers
  1. Vector v = new Vector();
  2. v=ctx.getAdminrole().getAttributeMultivalue();
  3.  
Now in the above code I am getting a set of strings in the object v.
Now i want to use the strings one by one for comparison.
So what type of code or loop i have to use to fetch the values stored in vector.

Any pointers in this regard will be very helpful
There is no need to create a new Vector if you're retrieving an existing one in the
next step. If you had used a generic vector you could've used the for-each loop:

Expand|Select|Wrap|Line Numbers
  1. Vector<String> v= ctx.getAdminrole().getAttributeMultivalue();
  2. ...
  3. for (String elem : v ) {
  4.    // do something with an 'elem' from the vector
  5. }
  6.  
kind regards,

Jos
May 27 '08 #2
There is no need to create a new Vector if you're retrieving an existing one in the
next step. If you had used a generic vector you could've used the for-each loop:

Expand|Select|Wrap|Line Numbers
  1. Vector<String> v= ctx.getAdminrole().getAttributeMultivalue();
  2. ...
  3. for (String elem : v ) {
  4.    // do something with an 'elem' from the vector
  5. }
  6.  
kind regards,

Jos
Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3.     public class setsubrole extends BLTHAdapter{
  4.         public void handleSetSubject(BLTHContext ctx) throws Exception 
  5.         {
  6.         try{
  7.         Vector v = new Vector();
  8.         v=ctx.getAdminRole().getAttributeMultiValue("CUSTOM10");
  9.         for(int i=0; i <= v.size();i++)
  10.  
  11.             {
  12.  
  13.             ctx.getAdminRole().setAttributeMultiValue("CUSTOM06",(Vector) v.elementAt(i) );    
  14.  
  15.             }
  16.         }
  17.  
  18.         catch(Exception e)
  19.         {
  20.  
  21.                 throw e;
  22.  
  23.         }
  24.  
  25.         }
  26.  
  27.  
  28.  
  29.     }
  30.  
This is my whole code. Intially in the vector v the values are string1 space string2 space string3
Now I want to fetch string1 from the vector v.
the error I am getting is java.lang.String
May 27 '08 #3
Laharl
849 Expert 512MB
A Vector holds Objects. Its access methods return Objects. Thus, you have to cast to String to call any String methods from entries in the Vector. Or, if you're using JDK > 1.5 (you should be), then you can use generics, eg a Vector<String>, to avoid all that.
May 27 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: J. Campbell | last post by:
I'm comfortable with arrays from previous programming, and understand the advantages of c++ vectors...I just don't understand how to use them :~( Can you help me to use a vector<string> in the...
5
by: Adrian | last post by:
Hi all, I am getting a warning compiling the following code using Borland C++ Builder 6, but I dont think I am doing anything wrong. When using g++ I get no warnings at all with a g++ -Wall...
3
by: andreykuzmenko | last post by:
I am trying to create a template class, which would store a vector of references to objects of the same class. Like: template<class _core_t> class Neuron { ///snipped private:...
2
by: Eric | last post by:
I am converting my VC++ MFC to Manage C++ and I am having trouble using the vector class. Here is my __gc class ....other headers for System classes .... #include <algorithm> #include...
0
by: Eric | last post by:
I'm also interested in finding out more about using vector graphics when designing the UI in Windows forms applications. I know a lot about GDI+ and raster graphics, but vector graphics is a new...
6
by: nabeel.girgis | last post by:
I'm creating a deck class which uses a card class. The card class is correct and works perfectly. One fo my member functions is to draw a card, but I'm having trouble removing the top card after...
3
by: capes | last post by:
Hi, I have a structure called Tissue and I use it in a matrix like this: vector < vector < Tissue* tissueArray(cRows); This whole function works great for a matrix size of 2X2 to 15X15....
4
by: Jim Langston | last post by:
I'm using a function like this: char TextBuffer; jGet_DropDown_Selected_Text( cc.ddSex, TextBuffer); Where the function is filling in the text buffer. I don't have access to the actual...
10
by: The Cool Giraffe | last post by:
I got a hint recently (guess where, hehe) and was directly pointed to the vector class. Now, i have no issues using that way but i'm concerned about the performance issue. Which is fastest...
3
by: vrsathyan | last post by:
Hi.., While executing the following code in purifier.., std::vector<int> vecX; vecX.clear(); int iCount = 0; { int iVal;
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.