-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path17 .String Methods.java
More file actions
53 lines (40 loc) · 1.65 KB
/
17 .String Methods.java
File metadata and controls
53 lines (40 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package test;
import java.util.Arrays;
import java.util.Scanner;
//import javax.swing.*;
//import java.lang.Math;
//import java.util.Random;
//import java.awt.Color; // abstract window toolkit
import java.util.Arrays;
public class main {
// String Methods.
// String Methods:
//
public static void main(String[] args) {
// TODO Auto-generated method stub
// Declare the Scanner library
Scanner scanner = new Scanner(System.in);
String words = "Hello its IA";
// length() : returns the length of the string
int len = words.length();
// charAt(int index) : returns the character at the specified index
char chr = words.charAt(0);
// substring(int beginIndex): returns a new string that is a substring of the original string,
// starting from the specified index.
String left_string = words.substring(6);
// toUpperCase(): returns a new string with all characters in uppercase.
String uppercase = words.toUpperCase();
// toLowerCase(): returns a new string with all characters in lowercase.
String lowercase = words.toLowerCase();
// trim(): returns a new string with leading and trailing white space removed.
String trimo = words.trim();
// replace(char oldChar, char newChar): returns a new string where all occurrences of the
// old character are replaced with the new character
String replaced = words.replace("its", "im");
// startsWith(String prefix): returns true if the string starts with the specified prefix,
// otherwise false.
boolean startwithhello = words.startsWith("Hello");
boolean startwithia = words.startsWith("ia");
System.out.println(startwithia);
}
}