answersLogoWhite

0

What are strings in java?

Updated: 8/9/2023
User Avatar

Wiki User

14y ago

Best Answer

The String class is defined in the java.lang package and hence is implicitly available to all the programs in Java. The String class is declared as final, which means that it cannot be subclassed. It extends the Object class and implements the Serializable, Comparable, and CharSequence interfaces.

User Avatar

Wiki User

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

Wiki User

14y ago


A string contains a series of characters.
A string can be seen as an array of characters.
There are some useful methods in the string class that make it more
useful than a character array to manipulate characters.

String str = "abc";
is equivalent to
char data[] = {'a', 'b', 'c'};

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

The String.format() method allows you format arguments (including strings) as a string.

The format specifiers for general, character, and numeric types have the following syntax: %[argument_index$][flags][width][.precision]conversion

Example:

String s = "foo";

String out = String.format("%-10s %d", s, 123);

System.out.println(out);

Output: (note spaces replaced with '.' to show whitespace).

foo........123

The negative width (e.g. -10) in the format causes the string to be left-justified. A positive width would be right-justified by default.

Note: System.out.printf() also uses the same mechanism to write a formatted string to output stream using the specified format string and arguments.

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

To declare a String in java:

String a = "hello";

In the above line, we created a String called a, and assigned the value hello to it.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What are strings in java?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How do you campaire Strings in java?

String class in Java has an 'equals' method that can be used to compare strings.


Are binary strings used in Java?

No if there was then java wouldn't have over 4 billion down loads


Which operator is used in java script to work on string?

If you want to check if two strings are equal you have to use string_b)alert("Strings are equal");elsealert("Strings are not equal");}


How can you prove the given string by user is array or not in java?

Strings and Arrays are two totally different data types in Java and they will not match with one another.


What are the restriction that are applied to operator overloading?

Java does not support user defined operator overloading.The operator '+' is overloaded in Java and can be used for adding both numbers and Strings.


Is String in java a class or object?

String is a pre-defined class in Java. For example: String s = new String("This is a string"); the variable s is now a String object since it was declared and initialized in the String class.


What is a string in java?

An object that stores an ordered set of characters (ie. "hello"). The String class represents character strings.


What is the purpose of Java Properties?

The Java Properties stores settings and configuration data such as user preferences or connection settings. It stores each parameter as a pair of strings, one being the name of the parameter and the other the value.


What is the Program for compare two strings using OR operator in java?

The String class includes two helpful methods: equals and compareTo.string1.equals(string2) will return true if the two strings contain the exact same charactersstring1.compareTo(string2) will return an int which describes the lexicographic relationship between the two strings. It will return a negative value if string1 is "less than" string2, a positive value if string1 is "greater than" string2, or zero if the two are equivalent strings.


What is the defualt value for String in java?

The default value for objects is null; I believe this would apply to a String, too, since Strings are objects.


Does passing static strings as parameters to a method create a copy of the String or passes its reference?

Java always follows a pass by value approach.


Why you use string s in the java program?

Strings are used to represent text data. This lets you work with names and other variables that hold text.