Search⌘ K
AI Features

Programs of String Operations

Explore how to perform essential string operations in Java such as copying one string to another, concatenating strings, searching for characters within arrays, and reversing strings. This lesson helps you gain practical skills by working through sample code and outputs, enhancing your understanding of string manipulation techniques in Java.

Copy a string

In Java, the individual characters in a string can be accessed but not assigned or modified.

The following program copies a string to another string:

Java
class Test
{
public static void main(String args[])
{
String src = "Just a string"; // The string to be copied
int lsrc = src.length();// Calculating the length of src
String dst = ""; // Creating an empty string
dst = src; // Copying data from src to dst
System.out.println("src: " + src);
System.out.println("dst: " + dst);
}
}

String concatenation

Concatenation means appending a string to another string. The ...