1. Java program to replace certain characters of a String
1. Java program to find the occurrences of distinct words from a file
You need to understand the basics of Java Streams. A stream is a sequence of data. A stream can be either 1. InputStream - read data from a source 2. OutputStream - write data to a destination Byte Stream - Java stream that is used to read/write data in the form of bytes.
public class Testing {
public static void main(String args[]) {
String str = "String";
char temp[] = str.toCharArray();
char charToBeChanged = 'g';
char changeChar = 'G';
char temp1[] = replaceCharacter(temp, charToBeChanged, changeChar);
for (int j = 0; j < temp1.length; j++) {
System.out.print(temp1[j]);
}
}
private static char[] replaceCharacter(char[] temp, char charToBeChanged, char changeChar) {
char temp1[] = new char[temp.length];
for (int i = 0; i < temp.length; i++) {
if (temp[i] == charToBeChanged) {
temp1[i] = changeChar;
} else {
temp1[i] = temp[i];
}
}
return temp1;
}
}
// Output
StrinG
1. Java program to find the occurrences of distinct words from a file
You need to understand the basics of Java Streams. A stream is a sequence of data. A stream can be either 1. InputStream - read data from a source 2. OutputStream - write data to a destination Byte Stream - Java stream that is used to read/write data in the form of bytes.
No comments:
Post a Comment