answersLogoWhite

0

A String is nothing but a bunch of characters one after the other whereas a character has a size of only '1'

So converting a string into a char is not possible. what you can do is form a character based on only one element from the string.

Ex:

String name = "Rocky";

char xyz = name.charAt(0);

now the char xyz will have one character from the String.

What else can I help you with?

Related Questions

How many bits does a Java char contain?

16 bits. Java char values (and Java String values) use Unicode.


What are the different between'a' and ''a in java string methods?

The difference between 'a' and "a" anywhere in Java is that 'a' is a primitive char type, while "a" is a String object.


How do you convert char to string?

Character.toString('c')


What is the different between char and string?

char is used in Java to enetr only one character but string is used to specify a whole sentence or a bunch of characters.


In java is A string the same thing as a char?

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.


How to convert lowercase to uppercase in java?

In Java you can invoke the toUpperCase()method on a string to convert it to a new string with all upper case characters.For example, "abc".toUpperCase() returns "ABC"Likewise, the static Character.toUpperCase(char ch) method takes a single character and returns the upper-case equivalent of that character (e.g. 'a' -> 'A').


How do you convert string to int in Java?

One can convert a string variable to an int variable in Java using the parse integer command. The syntax is int foo = Integer.parseInt("1234"). This line will convert the string in the parenthesis into an integer.


How can you convert byte to string in java?

To convert byte to String in java use the String(bytes, UTF-8); //example for one encoding type. You must know the special encoding that contains a variety of characters.


Java program to convert lowercase to uppercase?

You can use the toUpperCase() method on a String to convert any String to all uppercase.


How can someone convert string to int in Java?

To convert string to int in Java, the easiest way is to simply use the method Integer.parseInt(). For more information how to do this, refer to the integer class documents.


Write a java program to reverse the words in a sentence in place?

This is actually an interesting request. A "sentence" in Java would normally be stored in a String object. However, you also requested an "in place" sort, which is not possible to do with a String.Strings are an immutable type, which means that once its value is set a String can never change. If you try to change it, Java will actually be making an entirely new String in the background.Given all of the above, the next best thing we can do is look at a reversal of a character array.// This method will accept a String, convert it to a char[], reverse the char[], then convert// it back into a String to return.public static String reverseSentence(final String sentence) {// Get the character array of sentencefinal char[] sentenceChars = sentence.toCharArray();// Iterate through the first half of the array and swap each character with its// "mirrored" counterpart - first and last swap, second and second-to-last swap...final int halfLength = sentenceChars.length / 2;for (int i = 0; i < halfLength; ++i) {final char temp = sentenceChars[i];sentenceChars[i] = sentenceChars[sentenceChars.length - i - 1];sentenceChars[sentenceChars.length - i - 1] = temp;}// Use String.valueOf(char[]) to recreate a Stringreturn String.valueOf(sentenceChars);}


What is the code required to convert an integer variable to a string variable in Java?

There are several different methods to convert an integer variable to a string variable in Java. For example, one can use the following code to convert an integer variable to a string variable: Integer.toString(number)