Results 1 to 3 of 3
- 03-04-2013, 10:57 PM #1
Member
- Join Date
- Mar 2013
- Posts
- 2
- Rep Power
- 0
Use of variables in methods like charAt()
Hi.
I'm aware of creating methods like charAt() is one.
Random
What I'm confused about how it is possible for charAt() to use the string "s"? What's the deal? Does it parse the string to the class? There's probably an easy answer to this, but I've yet to see how it works, which is why I'm asking for help. A link to a tutorial answering my question would be awesome.Java Code:String s = "Random text"; System.out.println(s.charAt(2));
Thanks in advance.
- 03-04-2013, 11:08 PM #2
Senior Member
- Join Date
- Jan 2013
- Location
- United States
- Posts
- 667
- Rep Power
- 1
Re: Use of variables in methods like charAt()
The string s is an object of type String. So like any other object, there are methods which are specific to the class which operate on the object. In this case, String is backed by a char[] array. So when you pass an argument to charAt() it returns the character at that location in the array.
Regards,
JimThe Java™ Tutorial
YAT -- Yet Another Typo
- 03-04-2013, 11:48 PM #3
Member
- Join Date
- Mar 2013
- Posts
- 2
- Rep Power
- 0
Similar Threads
-
How to keep variables through multiple methods
By SethLasky in forum New To JavaReplies: 11Last Post: 07-26-2012, 03:35 AM -
Passing variables to methods
By KKorn429 in forum New To JavaReplies: 3Last Post: 05-21-2012, 12:40 AM -
Using variables in different methods
By squirmytoad in forum New To JavaReplies: 2Last Post: 01-10-2012, 08:04 PM -
using variables in multiple methods
By cagipple in forum New To JavaReplies: 2Last Post: 09-14-2011, 03:44 AM -
variables-methods
By Warren in forum New To JavaReplies: 1Last Post: 11-28-2007, 04:14 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks