Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

- - - - -

Objects..

downcast

  • Please log in to reply
3 replies to this topic

#1 Guest_idgeitman_*

Guest_idgeitman_*
  • Guest

Posted 19 April 2007 - 09:15 AM

Hey all,

I've been giving objects a try, but i tryed to make a little search function and it doesn't seem to be working out,


static void mod(Vector v) {
    
     System.out.print("Reg to search: ");   
      
      String readx = new String();
         Keyboard.skipLine();
         readx = Keyboard.readString();
        
        
        	for(int i = 0; i < v.size(); i++) {

             Object p = v.elementAt(i);
              car c2 = (car)p;	
              	
    if(c2.reg == readx) 
     	 System.out.println(c2.make + "\t:\t" + c2.reg + "\t:\t" + c2.numdays + "\t:\t" + "E " + c2.cost + "\n");
   
         }

Thats the main program code, The car class is has a String called "reg" inside it. What im trying to do is get it to downcast and then compare the readx to the c2.reg and if it matches, then print out that object,

Any help would be great!

Thanks,

~ Idgeitman
  • 0

#2 John

John

    CC Mentor

  • Moderator
  • 4450 posts
  • Location:New York, NY

Posted 20 April 2007 - 06:58 PM

are readx to the c2.reg strings?
  • 0

#3 Guest_idgeitman_*

Guest_idgeitman_*
  • Guest

Posted 22 April 2007 - 12:54 AM

c2.reg is also a string
  • 0

#4 John

John

    CC Mentor

  • Moderator
  • 4450 posts
  • Location:New York, NY

Posted 22 April 2007 - 07:42 PM

I believe strings are objects and should therefor use the .equals() method to compare rather than the == operator
  • 0





Also tagged with one or more of these keywords: downcast

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download