File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes How does this method work? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How does this method work?" Watch "How does this method work?" New topic
Author

How does this method work?

Olivier Legat
Ranch Hand

Joined: Nov 17, 2007
Posts: 176



The output is "his_".

What is the variable buf[] for? My teacher told me to put it but I don't know why!

Another thing I don't understand is why does it stop at the first "_"? Shouldn't it display "his_i"? (i.e. Up until index 5 since int end=5)


Olly
Raghavan Muthu
Ranch Hand

Joined: Apr 20, 2006
Posts: 3344

Originally posted by Olivier Legat:

What is the variable buf[] for? My teacher told me to put it but I don't know why!


The variable "buf" with the pair of square brackets "[]" means an array! A set of contiguous memory locations being used to store the similar kinda data value. Here in this case, you use a container to store a set of characters. so you need an array of characters.

In Java, you declare the array in this way!


Another thing I don't understand is why does it stop at the first "_"? Shouldn't it display "his_i"? (i.e. Up until index 5 since int end=5)


Well, end is 5 and start is 1. so, (end-start) will give you 4 (5-1=4 ). As the arrays always start with 0 instead of 1, you will get upto 4.

Does that help?


Everything has got its own deadline including one's EGO!
[CodeBarn] [Java Concepts-easily] [Corey's articles] [SCJP-SUN] [Servlet Examples] [Java Beginners FAQ] [Sun-Java Tutorials] [Java Coding Guidelines]
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19653
    
  18

Also, in nearly all API calls that need an end index, this end index is exclusive. So if you want characters 1 to 5, you need to give the end as 6.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Olivier Legat
Ranch Hand

Joined: Nov 17, 2007
Posts: 176

YAH! Helps loadz. Thanks
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How does this method work?
 
Similar Threads
I tried debug failing: trying to incle xml file contents to db table
creating a link
Difference between '+' and concat() method in String
Can I map a string buffer to a java class?
using byte array to copy contents of one file to another