This week's book giveaway is in the Java in General forum.
We're giving away four copies of Event Streams in Action and have Alexander Dean & Valentin Crettaz on-line!
See this thread for details.
Win a copy of Event Streams in Action this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

pls explain what is method does

 
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This i saw in a book and I couldnt understand what exactly this method does.




any help appreciated
 
Ranch Hand
Posts: 326
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it returns the index of a String object within a List object, if present.

Would the title of the book happen to be 'How Not to Write Java'?
 
Mary Wallace
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If i pass 1 then the method returns 1. If I pass 2 the method return 2.
am i rt?
So what is the purpose of this method?
I think this method doesnt do anything.
Am i missing something

 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Passing 1 and getting 1 is sort of a coincidence.

empindex.contains("1") - tells you whether "1" is in the vector

empindex.indexOf("1") - tells you what position it's in in the vector

This is silly code. A simple indexOf("1") would give you the same information without the invitation for disaster that comes with the magic number 99. What if the position of "1" really was position 99? This method would seem to tell you it was not found, which is wrong.

See the JavaDoc for Vector, read up on contains() and indexOf(). See if you can replace the body of this horror one line of code.

See the JavaDoc for the Collection interface and some of the classes in the "see also" section. See if you can avoid ever using Vector again.

Keep reading code and asking questions! Learning is fun!
[ November 03, 2004: Message edited by: Stan James ]
 
Ranch Hand
Posts: 295
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ray,

Originally posted by Ray Stojonic:

Would the title of the book happen to be 'How Not to Write Java'?



Could you please expand a bit on this comment?
 
Ray Stojonic
Ranch Hand
Posts: 326
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Ramaswamy Srinivasan:
Could you please expand a bit on this comment?



Okay

the original code, with my comments:


All this code is after is the index of an item in the list, which hardly needs to be broken out into it's own method.

So, unless an author was trying to demonstrate bad coding practices, my guess is that this code had another source.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!