-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStrings.java
More file actions
39 lines (32 loc) · 1.16 KB
/
Strings.java
File metadata and controls
39 lines (32 loc) · 1.16 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
package com.company;
public class Strings {
public static void main(String[] args) {
// Immutability - can't change string
// Mutability - can change string
// First Method
String s = "Hello world";
System.out.println(s);
//Second Method
char [] arr = {'i', 't', 'u'};
String ch = new String(arr);
System.out.println(ch);
//Third method
String [] string = {"Hello","World"};
for (int i=0;i<string.length;i++) {
System.out.println(string[i]);
}
//String length
int len = s.length();
System.out.println("Length of String s " + len);
//Merging two strings
String merge = "I am writing java";
String m = " program";
String k = merge.concat(m);
System.out.println("After merging two strings: " + k );
//Accessing string by index
String in = "Chinmay";
char access = in.charAt(0);
System.out.println("At 0th index of String: " + access);
System.out.println("Converting char to string : " + String.valueOf(arr));
}
}