Question

Java. Give some examples (3 or more) of uses of string variables and how you can...

Java.

Give some examples (3 or more) of uses of string variables and how you can relate to them in your coding projects

0 0
Add a comment Improve this question Transcribed image text
Answer #1

In java, string objects are immutable. Immutable simply means unmodifiable or unchangeable.

Once string object is created its data or state can't be changed but a new string object is created.

public class StringExamples {

  

   public static void main(String[] args) {

      

       // creating empty string

       String str1 = ""; // this string will be created in String Constant Pool

      

       String str2 = new String(); // creating empty string

                                   // this will be created in heap

      

       String st3 = "Alex";

      

       System.out.println(str2);

      

       String str4 = st3.substring(0, 2); // this will not change the original string content

                       // this will create new string, because strings are mutable

      

       System.out.println(str2);

       System.out.println(str4);

   }

}

Please let me knwo in case of any issue

Add a comment
Know the answer?
Add Answer to:
Java. Give some examples (3 or more) of uses of string variables and how you can...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT