#Do you always have to create an object for a string like String ex = new String(whatever))
26 messages · Page 1 of 1 (latest)
⌛ This post has been reserved for your question.
Hey @pliant maple! Please use
/closeor theClose Postbutton above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
"this is a string" is instantiating a string
new String("this is a string") is instantiating a string then instantiating another string by passing it to the String constructor
so new string
instantiates "this is a string"
and also instantiates ex
by passing "this is a string" to it?
oh hi chris :D
oh yea
how do you use a method
like in another class
how would you call it to use it
and would it be different if the method was static vs nonstatic (like belonging to an object)
new String(...) instantiates a new string based on the data
making a string literal, "text", is also instantiating a new string
yes, that changes where you access it from
you just call it from the appropriate context
System.out.println access the println instance method of PrintStream, the type of System.out
Uhh like
What if you had an add function
For an object
How would you call it in another class
you would need an instance of that object, suppose it's in a variable called obj, then you would call it like obj.add(...)
😐
u can just do String str = "string here"; no need to use new String()