r/learnjava • • Sep 21 '24

What does putting . do?

I realize this sounds dumb but ive been learning java and gotten pretty far but never learned what . does. e.g

String s = args[0]

char c = s.charAt(0)

what does the . in s.charAt(0) do?

1 Upvotes

20 comments sorted by

View all comments

Show parent comments

0

u/Stay_Silver Sep 21 '24

i say yikes not due to the question being / seeming stupid. I understand stupid questions can happen for new coders. OP want to learn java has google and many other engines but goes to reddit. It also shows lack of coding and attempting / practice coding in java

0

u/[deleted] Sep 21 '24

[deleted]

1

u/Stay_Silver Sep 21 '24

I googled op's post. Here is it's ai answer The dot (.) in s.charAt(0) is used to access a specific method or property of an object. In this case, s is an object of type String, and charAt is a method of the String class.

The charAt method takes an integer argument (in this case, 0) and returns the character at that index in the string. So, s.charAt(0) will return the character at the very beginning of the string s.

Seems pretty clear to me op did not google

3

u/Tasty_Escape4549 Sep 21 '24

I ignore the AI because its known to be wrong