answersLogoWhite

0


Best Answer

No.

A char is a single Unicode character. It is stored as a primitive (i.e., non-object) data. A string can be considered as an array of chars - Java stores it as an object.

No.

A char is a single Unicode character. It is stored as a primitive (i.e., non-object) data. A string can be considered as an array of chars - Java stores it as an object.

No.

A char is a single Unicode character. It is stored as a primitive (i.e., non-object) data. A string can be considered as an array of chars - Java stores it as an object.

No.

A char is a single Unicode character. It is stored as a primitive (i.e., non-object) data. A string can be considered as an array of chars - Java stores it as an object.

User Avatar

Wiki User

14y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

14y ago

No.

A char is a single Unicode character. It is stored as a primitive (i.e., non-object) data. A string can be considered as an array of chars - Java stores it as an object.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: In java is A string the same thing as a char?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

How does a 'string' type string differ from a c-type string?

A char is a single character. A String is a collection of characters. It may be empty (zero characters), have one character, two character, or many characters - even a fairly long text.The single quote (') is used to deliniate a character during assignment:char someChar = 'a';The double quote (") is used to delineate a string during assignment:String someString = new String("hello there");Note that char is a primitive data type in Java, while String is an Object. You CANNOT directly assign a char to a String (or vice versa). There is, however, a Character object that wraps the char primitive type, and Java allows method calls to be made on the char primitive (automagically converting the char to Character before doing so).i.e. these ALL FAIL:someString = SomeChar;someString = new String(someChar);However, these WILL work:someString = Character.toString(someChar);someString = someChar.toString();Also note that a String is a static memory allocation, while a character's is dynamic. By that, I mean that when a String is created, it is allocated a memory location exactly big enough to fit the assigned string. Any change to that String forces and entirely new memory location to be allocated, the contents of the old String copied in (with the appropriate changes), and the old String object subject to garbage collection. Thus, making changes to a String object are quite inefficient (if you want that kind of behaviour, use StringBuffer instead).A character is allocated but once; all subsequent changes to a character variable simply overwrite that same memory location, so frequent changes to a character variable incur no real penalty.


What do you mean by string in c language?

Character arrays or pointers to character are termed as strings in c language. Like:char arr[10] = {'s', 't', 'i', 'n', 'g'};char *pchar = "string";Above answer is the first answer for the questionBut there is a lot of difference between character array and string.string means a group of characters .And string is enclosed between double quotation marks i.e(" ") .Declaration of string is same as of char array ,which is as followschar str[20];And initialization is different from that of character arrayinitialization:-char str[7]={"vardhan"};


What is pallendrome in java?

palindrome in every language means same. it means on reversing a number or string, if we get the same number or string as the case may be ,then the number or string is called palindrome. eg: 1221,111,252 or LIRIL,MADAM etc .


How do you copy a string from one method into another string in another method in java?

You can have two String variables (note that String variables are object references) refer to the same String object like so: String str1 = "Hello"; String str2 = str1; Now the str1 and str2 are references for the same String object containing the word "Hello". If you actually want a new String object with a copy of the contents of the original String, you use the String constructor that takes a String argument, like so: String str3 = new String(str1); Now str1 and str3 refer to SEPARATE String objects that happen to contain the same sequence of characters (the word "Hello"). Since Strings objects in Java are immutable, they can be shared without worrying about the contents used by one variable being upset by the use through another variable as might happen with char[] arrays in C or C++ so the first method is probably sufficient for most cases.


WAP in java to take alphabet and print ascii value for it?

Remember that chars in Java are just a special version of ints. Cast the char as an int and you get the Unicode value for it. Fortunately, the group of characters including letters and numbers have the same value in both encoding systems. for (char letter = 'a'; letter <= 'z'; ++letter) { System.out.println("ASCII of " + letter + " = " + (int) letter); }

Related questions

What is short char?

Either syntax error or the same thing as char.


How does a 'string' type string differ from a c-type string?

A char is a single character. A String is a collection of characters. It may be empty (zero characters), have one character, two character, or many characters - even a fairly long text.The single quote (') is used to deliniate a character during assignment:char someChar = 'a';The double quote (") is used to delineate a string during assignment:String someString = new String("hello there");Note that char is a primitive data type in Java, while String is an Object. You CANNOT directly assign a char to a String (or vice versa). There is, however, a Character object that wraps the char primitive type, and Java allows method calls to be made on the char primitive (automagically converting the char to Character before doing so).i.e. these ALL FAIL:someString = SomeChar;someString = new String(someChar);However, these WILL work:someString = Character.toString(someChar);someString = someChar.toString();Also note that a String is a static memory allocation, while a character's is dynamic. By that, I mean that when a String is created, it is allocated a memory location exactly big enough to fit the assigned string. Any change to that String forces and entirely new memory location to be allocated, the contents of the old String copied in (with the appropriate changes), and the old String object subject to garbage collection. Thus, making changes to a String object are quite inefficient (if you want that kind of behaviour, use StringBuffer instead).A character is allocated but once; all subsequent changes to a character variable simply overwrite that same memory location, so frequent changes to a character variable incur no real penalty.


String?

For the majority of languages, a string is a primary data type that denotes an ordered series of one or more characters (a character is an item that can be input or output - in general, they are displayable in some form, but there are character systems which have non-displayable characters for reasons of history). One character can only be represented by a single 8-bit byte in some languages (like C), which corresponds to an ASCII code entry. A single character (char) and a string (really an array of characters ended by a NULL (zero) character) both have their data types in the programming language C. Other languages, like Python 3, for instance, define a character as any Unicode item ranging in size from one to four bytes. The runtime environment (JRE), made up of the JVM, is a general-purpose, concurrent, object-oriented, class-based programming language called Java. We shall be talking about Java String, a novel idea, in this blog. Each character in a string is a separate unit. A line, however, is an object that represents a series of characters in Java. A string object is made using the a class named String. A String object can be created in given ways: Using a literal string Java, Double quotes are used to produce string literals. For instance: s="Welcome" string; Using a new keyword When creating a Java String, the "new" keyword is used. For instance: s = new String ("Welcome"); It produces two objects (in a heap and the String pool), as well as one reference variable whose value, "s," refers to the object in a heap. Let's now examine the Java String pool concept. Java String Pool A group of Strings that are kept in heap memory collectively comprise the Java String pool. String Pool initially determines whether the item is already present in the pool or not whenever a new object is formed. If it is, the variable receives the same reference back; otherwise, a new object will be generated Java String Methods Java String length(): The Java String length() function provides the string's length information. It gives the total number of characters in the String as a count. Java's compareTo(): The given string is compared to the current string using the Java String compareTo() function. It is a method of the "Comparable" interface that the String class implements. Java String concat(): This method joins a particular string to the end of other string and then outputs the resulting combined string. It is comparable to adding a new string. Java String IsEmpty(): This method determines whether or not the String is empty. It returns true if the java String is Empty and false otherwise. toLowerCase() : All of the characters in the String are converted to lowercase using the Java String toLowerCase() function. Java's toUpper() method: All of the characters in the String are changed to the upper case via the Java String toUpperCase() function. Java String Replace(): This method returns a string with all the old characters or characters in a CharSequence replaced with new characters. contains(): The Java contains() method looks through the string's characters in order. It returns true if the character sequences are detected; otherwise, it returns false. String to CharArray() in Java: This method turns the given Java String into a character array by first calculating the length of the string, including any spaces, and then producing an array of the same name as a char type. String IsEmpty() in Java: This method determines whether or not the String is empty. The String returns true if its length is zero; otherwise, it returns false. StringBuffer and StringBuilder are two utility classes offered by Java. Let's examine what makes these two utility classes distinct from one another: Mutable classes include StringBuffer and StringBuilder. In contrast to StringBuilder operations, which are not thread-safe, StringBuffer operations are synchronized. StringBuffer should be used in the single-threaded environment when many other threads are working on the same String and StringBuilder. StringBuilder performs faster than StringBuffer Because there is no synchronization overhead, That is all there is to know about string for a novice. I hope this article answers your query.


What is string buffer in java?

StringBuffer is java class available in java.lang package which provides mutable String object where String is immutable class. The methods of this class like reverse(), append(),insert() gives facility to insert data of the same object.


Is java and coffee the same thing?

Yes, they are synonyms.


What do you mean by string in c language?

Character arrays or pointers to character are termed as strings in c language. Like:char arr[10] = {'s', 't', 'i', 'n', 'g'};char *pchar = "string";Above answer is the first answer for the questionBut there is a lot of difference between character array and string.string means a group of characters .And string is enclosed between double quotation marks i.e(" ") .Declaration of string is same as of char array ,which is as followschar str[20];And initialization is different from that of character arrayinitialization:-char str[7]={"vardhan"};


What is pallendrome in java?

palindrome in every language means same. it means on reversing a number or string, if we get the same number or string as the case may be ,then the number or string is called palindrome. eg: 1221,111,252 or LIRIL,MADAM etc .


How do you copy one string to another without using function in c plus plus?

If you're using the std::string, why don't you just create another string instance like this: std::string hello = "hello"; std::string hello1; hello1 = hello; This will have copied the contents of the variable hello into hello1; char *psz1 = "This is a test."; char *psz2 = "..............."; // note - must be same or greater number of characters as psz1 char *p1 = psz1; char *p2 = psz2; while ((*p2++ = *p1++) != '\0'); // copy p1 to p2 Note: This is a trivial example, and might not work on most modern compilers that treat string literals as const or that place them into read-only memory. To solve this you need to replace the second line with ... char *psz2 = new char[16]; ... and then test to make sure that psz1 != NULL.


How you convert int to string in jsp?

The same way you would in a regular java program. int i = 10; String s = i + ""; after the above line of code the variable s will have "10" as a string value...


How do you copy a string from one method into another string in another method in java?

You can have two String variables (note that String variables are object references) refer to the same String object like so: String str1 = "Hello"; String str2 = str1; Now the str1 and str2 are references for the same String object containing the word "Hello". If you actually want a new String object with a copy of the contents of the original String, you use the String constructor that takes a String argument, like so: String str3 = new String(str1); Now str1 and str3 refer to SEPARATE String objects that happen to contain the same sequence of characters (the word "Hello"). Since Strings objects in Java are immutable, they can be shared without worrying about the contents used by one variable being upset by the use through another variable as might happen with char[] arrays in C or C++ so the first method is probably sufficient for most cases.


Are the three declaration char a char a and char c same?

Yes.


WAP in java to take alphabet and print ascii value for it?

Remember that chars in Java are just a special version of ints. Cast the char as an int and you get the Unicode value for it. Fortunately, the group of characters including letters and numbers have the same value in both encoding systems. for (char letter = 'a'; letter <= 'z'; ++letter) { System.out.println("ASCII of " + letter + " = " + (int) letter); }