-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExample3.java
More file actions
46 lines (41 loc) · 1.7 KB
/
Example3.java
File metadata and controls
46 lines (41 loc) · 1.7 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
package com.tutorial.def;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
public class Example3 {
public static void main(String[] args) {
int i =0;
String str = "name it once";
str = new String("Changed");
str += " hello!";
System.out.println(str);
System.out.println(str.length() + " " + str.substring(0, 5) + " " + str.indexOf("hello"));
String theString = "is this good or this is bad";
String subString = "is";
int index = theString.indexOf(subString);
while (index != -1){
System.out.println(theString + ", " + index + ", " + subString);
index = theString.indexOf(subString, index + 1);
}
System.out.println("lastIndexOf() " + " " + subString + " " +theString.lastIndexOf(subString));
String one = "abc";
String two = "def";
String three = "abd";
System.out.println(one.compareTo(two));
System.out.println(one.compareTo(three));
System.out.println(two.compareTo(three));
String str1 = "This is a byte test for getByte() method.";
byte[] bytes1 = str1.getBytes();
byte[] bytes2 = str1.getBytes(StandardCharsets.UTF_8);
//byte[] bytes3 = str1.getBytes(Charset.forName("UTF-16"));
byte[] bytes3 = str1.getBytes(Charset.forName("UTF-16"));
System.out.println(bytes3.length + ", " + str1.length());
/*for (byte b:
bytes3){
System.out.println(b);
}*/
String input = "Hey, \\n This is not normally a line break.";
System.out.println(input);
//String output = input.translateEscapes();
//System.out.println(output);
}
}