Java - Are Strings Arrays?
Go to solution
Solved by Tazman192,
6 minutes ago, IAmLamp said:How is that a new object though?
I added a little more to my post to explain. I'll add a little more here.
Say you create the string:
String x = "foo";
This is implicitly saying:
String x = new String("foo");
When you want to change x to "bar:
x = "bar";
This is again implicitly saying:
x = new String("bar")
Meaning, because we used the "new" keyword, we have created a NEW String object, and we have pointed an existing variable to point to this newly created object. This is opposed to a mutable type such as an int - you don't implicitly create a new int everytime (or at all - int's aren't objects, they're primitive), you overwrite your existing int..
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now