aspose file tools*
The moose likes Beginning Java and the fly likes pls explain what is method does Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "pls explain what is method does" Watch "pls explain what is method does" New topic
Author

pls explain what is method does

Mary Wallace
Ranch Hand

Joined: Aug 25, 2003
Posts: 138
This i saw in a book and I couldnt understand what exactly this method does.




any help appreciated
Ray Stojonic
Ranch Hand

Joined: Aug 08, 2003
Posts: 326
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

Joined: Aug 25, 2003
Posts: 138
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

Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
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 ]

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Ramaswamy Srinivasan
Ranch Hand

Joined: Aug 31, 2004
Posts: 295
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

Joined: Aug 08, 2003
Posts: 326
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: pls explain what is method does