-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathStringMethods.java
More file actions
52 lines (48 loc) · 2.53 KB
/
Copy pathStringMethods.java
File metadata and controls
52 lines (48 loc) · 2.53 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
package Java_basic_Programs;
import java.sql.SQLOutput;
import java.util.Locale;
import java.util.Scanner;
public class StringMethods {
public static void main(String[] args) {
// String a = "Akash";
// System.out.println(a);
// String a1 = new String("Akash");
// System.out.println(a1);
// Strings in Java is immutable so we can not change the string but we can do so by copping the string into
// another variable
// System.out.println(a.length()); // use to find the length of string
// System.out.println(a.toLowerCase(Locale.ROOT)); // to convert into lower case
// System.out.println(a.toUpperCase(Locale.ROOT)); // to convert into upper case
// System.out.println(a.compareTo("Akash")); // for comparing strings
// System.out.println(a.concat(" Deep")); // for concatenating strings
// System.out.println(a.equals("Akash")); // for checking equal
// System.out.println(a.contains("Aka")); // for checking sub-string in given string
//
//
// String s1 = " Akash ";
// System.out.println(s1);
// System.out.println(s1.trim()); // for trimming the string
// String name = "Akash Deep Vishwakarma";
// String sub_name = name.substring(3); // prints sub-string from the given index number of the string
// System.out.println(sub_name);
// System.out.println(name.substring(6,11)); // it prints sub-string from index start to (end-1)
//
// String Replaced_name = name.replace("A","Pra"); // for replacement of string in the given string
// System.out.println(Replaced_name);
//
// System.out.println(name.startsWith("A")); // returns true if it starts with given character
// System.out.println(name.endsWith("A")); //returns true if it ends with given character
//
// System.out.println(name.charAt(3)); // returns character at given index
//
// System.out.println(name.indexOf("s")); // returns index value of given character. It returns first occurance only
// System.out.println();
// String naam = "Harryrry";
// System.out.println(naam.indexOf("rry",4)); // it will start from index (4+1). returns
// // -1 if it does not find the sub-string or character in the given string.
//
// System.out.println(naam.lastIndexOf('r')); // returns last index of given character in the string
//
// System.out.println(naam.equalsIgnoreCase("HARRYRry"));
}
}