Java Strings: The Basics

One long section of code outlining how to achieve some basic string handling objectives in Java. Currently trying to get to grips with this language after spending far too many years concentrating on C++. Each technique is demonstrated with a code snippet. As with a lot of my other stuff, any new stuff I find useful will get added at a later date:

package stringdemos;
import java.util.*;

public class StringDemos
public static void main(String[] args)
// Initialize string
String greeting = “Hello world!”;
System.out.println( greeting );

// String length
int len = greeting.length();

// Copy string into temporary character array
char[] tempCharArray = new char[len];
for (int i = 0; i

Leave a Reply