├── A.java ├── M1.java ├── M10.java ├── M11.java ├── M12.java ├── M2.java ├── M3.java ├── M4.java ├── M5.java ├── M6.java ├── M7.java ├── M8.java └── M9.java /A.java: -------------------------------------------------------------------------------- 1 | package strings_app1; 2 | 3 | public class A { 4 | public static void main(String[] args) { 5 | String s1 = "hello mom u r my love"; 6 | System.out.println(s1); 7 | char[] c1 = s1.toCharArray(); 8 | char[] c2 = new char[s1.length()]; 9 | int j=0; 10 | for(int i=0; i < c1.length - 1;i++) { 11 | if(c1[i]!=' ') { 12 | if(c2[j] == ' ') { 13 | j++; 14 | } 15 | c2[j] = c1[i]; 16 | j++; 17 | } 18 | } 19 | s1=new String(c2); 20 | System.out.println(s1); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /M1.java: -------------------------------------------------------------------------------- 1 | package strings_app1; 2 | 3 | public class M1 { 4 | public static void main(String[] args) { 5 | String s1 = new String("hello i am king"); 6 | String s2 = "hello"; 7 | System.out.println(s1); 8 | System.out.println(s2); 9 | 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /M10.java: -------------------------------------------------------------------------------- 1 | package strings_app1; 2 | 3 | public class M10 { 4 | public static void main(String[] args) { 5 | String s1 = "hello"; 6 | 7 | char c1 = s1.charAt(0); 8 | char c2 = s1.charAt(1); 9 | char c3 = s1.charAt(2); 10 | char c4 = s1.charAt(3); 11 | char c5 = s1.charAt(4); 12 | 13 | System.out.println(c1); 14 | System.out.println(c2); 15 | System.out.println(c3); 16 | System.out.println(c4); 17 | System.out.println(c5); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /M11.java: -------------------------------------------------------------------------------- 1 | package strings_app1; 2 | 3 | public class M11 { 4 | public static void main(String[] args) { 5 | String s1 = "abcd"; 6 | 7 | System.out.println(s1.indexOf('b')); 8 | System.out.println(s1.indexOf('a')); 9 | System.out.println(s1.indexOf('c')); 10 | System.out.println(s1.indexOf('d')); 11 | System.out.println(s1.indexOf('e')); 12 | System.out.println(s1.charAt(2)); 13 | } 14 | } -------------------------------------------------------------------------------- /M12.java: -------------------------------------------------------------------------------- 1 | package strings_app1; 2 | 3 | public class M12 { 4 | public static void main(String[] args) { 5 | String s1 = "abcdabcd"; 6 | int i = s1.indexOf('a'); 7 | int j = s1.indexOf('b'); 8 | int k = s1.indexOf('c'); 9 | int l = s1.indexOf('d'); 10 | 11 | 12 | System.out.println(i); 13 | System.out.println(j); 14 | System.out.println(k); 15 | System.out.println(l); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /M2.java: -------------------------------------------------------------------------------- 1 | package strings_app1; 2 | 3 | public class M2 { 4 | public static void main(String[] args) { 5 | String s1 = "hello "; 6 | System.out.println(s1); 7 | System.out.println(s1.length()); 8 | } 9 | 10 | /*Strings ==> length() 11 | arrays ==> length 12 | collection classes ==> size() 13 | */ 14 | } 15 | -------------------------------------------------------------------------------- /M3.java: -------------------------------------------------------------------------------- 1 | package strings_app1; 2 | 3 | public class M3 { 4 | public static void main(String[] args) { 5 | String s1 = "hello"; 6 | // 0123 7 | System.out.println(s1); 8 | System.out.println(s1.length()); 9 | for(int i =0;i=0;i--) { 10 | System.out.print(s1.charAt(i)); 11 | } 12 | } 13 | } 14 | 15 | -------------------------------------------------------------------------------- /M5.java: -------------------------------------------------------------------------------- 1 | package strings_app1; 2 | 3 | public class M5 { 4 | public static void main(String[] args) { 5 | String s1 = "hello"; 6 | for(int i = 0;i=0;i--){ 7 | System.out.print(s1.charAt(i) + ", "); 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /M7.java: -------------------------------------------------------------------------------- 1 | package strings_app1; 2 | 3 | public class M7 { 4 | public static void main(String[] args) { 5 | String s1 = "hello Indians"; 6 | // 01234567890 7 | System.out.println(s1.length()); 8 | System.out.println(s1.charAt(s1.length()-1)); 9 | System.out.println("read all the characters in the forward direction"); 10 | for(int i =0;i0;i--) { 16 | System.out.println(s1.charAt(i)+","); 17 | } 18 | for(int k=s1.length()-1;k>0;k--) { 19 | System.out.print(s1.charAt(k)); 20 | } 21 | System.out.println(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /M8.java: -------------------------------------------------------------------------------- 1 | package strings_app1; 2 | 3 | import java.util.Scanner; 4 | 5 | public class M8 { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | System.out.println("Enter a string"); 9 | String s1 = sc.nextLine(); 10 | System.out.println(s1.length()); 11 | System.out.println("read all the characters in the forward direction"); 12 | for(int i =0;i=0;j--) { 17 | System.out.print(s1.charAt(j)); 18 | } 19 | System.out.println(s1); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /M9.java: -------------------------------------------------------------------------------- 1 | package strings_app1; 2 | 3 | public class M9 { 4 | public static void main(String[] args) { 5 | String s1 = "hello"; 6 | System.out.println(s1); 7 | } 8 | } --------------------------------------------------------------------------------