forked from janbodnar/Java-Advanced
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringElements.java
More file actions
32 lines (21 loc) · 860 Bytes
/
StringElements.java
File metadata and controls
32 lines (21 loc) · 860 Bytes
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
package com.zetcode;
public class StringElements {
public static void main(String[] args) {
char[] crs = {'Z', 'e', 't', 'C', 'o', 'd', 'e' };
String s = new String(crs);
char c1 = s.charAt(0);
char c2 = s.charAt(s.length()-1);
System.out.println(c1);
System.out.println(c2);
int i1 = s.indexOf('e');
int i2 = s.lastIndexOf('e');
System.out.println("The first index of character e is " + i1);
System.out.println("The last index of character e is " + i2);
System.out.println(s.contains("t"));
System.out.println(s.contains("f"));
char[] elements = s.toCharArray();
for (char el : elements) {
System.out.println(el);
}
}
}