answersLogoWhite

0

Strings, which are widely used in Java programming, are a sequence of characters. In the Java programming language, strings are objects. The Java platform provides the String class to create and manipulate strings. Creating Strings The most direct way to create a string is to write: String greeting = "Hello world!"; In this case, "Hello world!" is a string literal-a series of characters in your code that is enclosed in double quotes. Whenever it encounters a string literal in your code, the compiler creates a String object with its value-in this case, Hello world!. As with any other object, you can create String objects by using the new keyword and a constructor. The String class has 11 constructors that allow you to provide the initial value of the string using different sources, such as an array of characters: char[] helloArray = { 'h', 'e', 'l', 'l', 'o', '.'}; String helloString = new String(helloArray); System.out.println(helloString); The last line of this code snippet displays hello. Note: The String class is immutable, so that once it is created a String object cannot be changed. The String class has a number of methods, some of which will be discussed below, that appear to modify strings. Since strings are immutable, what these methods really do is create and return a new string that contains the result of the operation.

User Avatar

Wiki User

16y ago

What else can I help you with?

Related Questions

How do you accept a string by using getch() function with an example?

explain about function call


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)


What makes a violin string higher in quality than another violin string?

It depends on the company who made the string. Different companies use different materials and methods of making strings.


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.


A C program to print the number of words from given String?

/*We can calculate this with a lot of methods I'll explain only one of them */ *str = "abcd"; // this is a input string printf("%d", strlen(str));


What is the user of stringbufer class explain how it is different from a string class?

A StringBuffer is similar to a String with a few differences:String objects are immutable while StringBuffer objects can be modifiedIf your code involves string manipulation, string buffer is faster than strings


Explain any 8 difference between overloading and overriding?

Overriding methods that are in the parent class is to redefine them in the current (child) class in a different way. Like if you're extending a class but you don't like the behavior of one method in that class, you can override that method and write your own code. Overloading a method in the current class is defining another copy of the method with different signature. They call them overloaded methods. This is an example of overloaded methods: myMethod(int i, int b){ .... } myMethod(String s) { ... } myMethod(boolean b) {...} Hope that was clear


Java program convert the inputed words into its upper case or lower case form?

There are methods in the String class; toUppercase() and toLowerCase(). i.e. String input = "Hello!"; String upper = input.toUpperCase(); //stores "HELLO!" String lower = input.toLowerCase(); //stores "hello!" -Note: these methods are NOT modifier methods therefore the original string is still "Hello!"


Explain different string functions handled in c sharp?

C#:String FunctionsThe methods and properties of the String type include:String s="Sourav was here"Example Value Detailss+" once" "Sourav was here once" The strings are concatenated using +s.Equals("another") false Also s == "another" Tests for equalitys.IndexOf("was") 6 Returns -1 if the substring isnot there.s.Length 14 The number of characterss.Split(" ") ["Andrew","was","here"] Returns an array of String.s.Substring(2,7) "urav wa" Characters from position 2. 7characters are takens.ToUpper() "SOURAV WAS HERE" Also .toLowerCase()


Can you provide an example of a string permutation and explain how it can be used in a real-world scenario?

A string permutation is a rearrangement of the characters in a string. For example, the string "abc" can be permuted as "acb", "bca", etc. In a real-world scenario, string permutations can be used in cryptography to create unique encryption keys or in computer algorithms to generate all possible combinations of a set of characters for tasks like password cracking or data analysis.


How do you string a tennis racquet?

You need a stringing machine and some new string to start with. Then it all depends on the string pattern you are trying to do. Most Club Players use a one piece pattern. You need to start with the mains and then move onto the crosses. tensioning each string as you go then tying off at the last string. Its pretty confusing! Lots of pros use different string combinations as well so can be strung with different methods. .


How do you pass objects to methods?

The same way as you pass a non-object parameter; for example: String x = "Hello"; doSomething(x); (In Java, a String is an object, but this works just as well with an object created with the "new" keyword.)