forked from AndrewProgramming/JavaTutorialCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringDemo.java
More file actions
43 lines (26 loc) · 1.27 KB
/
StringDemo.java
File metadata and controls
43 lines (26 loc) · 1.27 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
package stringdemo;
public class StringDemo {
public static void main(String[] args) {
StringDemo stringDemo = new StringDemo();
System.out.println(stringDemo.toString());
String s = new String("Andrew Programming!");
System.out.println("s:" + s);
char[] chars = {'J', 'A', 'V', 'A'}; //Character Array
String s1 = new String(chars); //Creating a String object by passing character array as an argument
System.out.println("s1:" + s1);
String s11 = new String(chars, 2, 2);
System.out.println("s11:" + s11);
StringBuffer strBuff = new StringBuffer("abc");
String s2 = new String(strBuff); //Creating a string object by passing StringBuffer type as an argument
System.out.println("s2:" + s2);
StringBuilder strBldr = new StringBuilder("s builder");
String s3 = new String(strBldr); //Creating a string object by passing StringBuilder type as an argument.
System.out.println("s3:" + s3);
String s5 = "abc";
String s6 = "abc" + "def";
String s7 = "123" + "A" + "B";
System.out.println(s5); //Output : abc
System.out.println(s6); //Output : abcdef
System.out.println(s7); //Output : 123AB
}
}