Introduction To Programming In Java/Strings

Strings are a collection of characters implemented under the String class. However, they may also appear directly in the source code.

String operations

The only operation permitted on a string is the operator. In the context of a string, this operator performs concatenation. The value on the right, a string, is appended to the string on the left.

Strings can also be concatenated with integers or other numbers. If this is the case, the variable or object is automatically converted to a string.

String performance[]

Even though you may be able to concatinate strings indefinitely, this is not the best means to do what you want. Since strings are immutable objects, attemtping to change a string will create a new string object, and making identical copies of the strings.

If you need to constantly append characters to a string, you may want to use a StringBuilder class.

 

String constructors

You can also create strings using these methods. Explanation to below every example of the String constructor.

	
String aString= new String();
// aString is a reference to an empty string. aString can be any name that you want to name the variable
	
String aGreeting;
// aGreeting is reference to a String
aGreeting = new String("Hello world");


Greeting1 = "Hello world";
// Shortcut for constructing String objects.
String Greeting2 = new String(Greeting1);
// Greeting2 is a copy of the String Greeting1
Project: Introduction to Programming in Java
Previous: Boolean Variables -- Introduction to Programming in Java/Strings -- Next: Java Classes

This article uses material from the Wikipedia page available here. It is released under the Creative Commons Attribution-Share-Alike License 3.0.



Introduction_to_Programming_in_Java/Strings
 

Manage research, learning and skills at IT1me. Create an account using LinkedIn to manage and organize your IT knowledge. IT1me works like a shopping cart for information -- helping you to save, discuss and share.


  Contact Us  |  About IT1me.com |  IT Training & References |  IT Careers |  IT Hardware |  IT Software |  IT Books