Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6829017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:27:04+00:00 2026-05-26T22:27:04+00:00

A String is represented as objects in Java. Accordingly, an object contains values stored

  • 0

A String is represented as objects in Java. Accordingly, an object contains values stored in instance variables within the object. An object also contains bodies of code that operate upon the object. These bodies of code are called methods.


Objects that contain the same types of values and the same methods are grouped together into classes. A class may be viewed as a type definition for those objects. Accordingly, how is a String in Java represented? Let’s consider the following code snippet in Java.

 final public class Main
 {
    public static void main(String[] args)
    {
        String s="black lion";
        String s1=new String(s);

        System.out.println(s.toUpperCase());
        System.out.println("black lion".toUpperCase());
        System.out.println(s1.toUpperCase());
    }
}

The above code displays the String after converting it into uppercase. In this statement String s="black lion"; , Where is the String being assigned. Is it being assigned into an instance variable within the String class or somewhere? and in this statement "black lion".toUpperCase();. Is it an object of the String class? How?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T22:27:05+00:00Added an answer on May 26, 2026 at 10:27 pm

    A string is a char[] containing a series of UTF-16 code units, an int offset into that array, and an int length.

    I think the source of your confusion is the idea that

    String s
    

    creates a string that is assigned into.

    It does not. It creates space for a string reference. Assigning copies references around but does not modify the objects to which those references refer.

    You should also be aware that

    new String(s)
    

    doesn’t really do anything useful. It merely creates another instance backed by the same array, offset, and length as s. There is very rarely a reason to do this so it is considered bad practice by most Java programmers.

    Java double quoted strings like "my string" are really references to interned String instances so "foo" is a reference to the same String instance regardless of how many times it appears in your code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a system that entities (from database, represented as Java objects through ORM)
I want to check whether a java.lang.reflect.Type instance represents an Emum object or not.
I need to convert a string time stamp value into Java Date object. The
Every time I create a new Dog object on a main Java class, I
The problem can be found in the following code: def debug[T](format: String, arg1:T, arg2:Any,
I'm trying to use Jackson to convert some JSON data into Java objects ,a
Why I cannot do this in java? Object[] o = (Object[])(new int[]{0,1,2,3.14,4}); I have
package timeToys; import java.util.regex.Pattern; ** * A DayTime is an immutable object that stores
From the Java tutorial : Finally, there's also a special kind of literal called
I have a user defined class, say import java.util.Calendar; public class Employee{ private String

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.