-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathstrings.html
More file actions
77 lines (70 loc) · 3.19 KB
/
strings.html
File metadata and controls
77 lines (70 loc) · 3.19 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="https://javaalmanac.io/almanac.min.css">
</head>
<body>
<div class="content" id="content">
<sandbox version="java17" mainclass="Main" preview="true" v-cloak>
<sandbox-source name="Main.java">import java.util.*;
public class Main {
public static void main(String[] args) {
String name = "Αγαμέμνων";
String firstname = "Οδυσσέας";
String surname = "Ελύτης";
System.out.println(firstname + " " + surname);
String s1="Καλήν εσπέραν άρχοντες";
String s2=" άρχοντες";
System.out.println(s1.equals(s2)); // έλεγχος ισότητας
System.out.println(s1.compareTo(s2)); // σύγκριση, == 0 σημαίνει ίσα, < 0 σημαίνει το s1 είναι πριν το s1, > 0 σημαίνει το s1 είναι μετά το s2
System.out.println(s1.length()); // μήκος αλφαριθμητικού
System.out.println(s1.toLowerCase());
System.out.println(s1.contains("Καλήν"));
System.out.println(s1.indexOf(s2)); // η λέξη "άρχοντες" βρίσκεται στη θέση 13 της συμβολοσειράς s1
System.out.println(s1.substring(6,13)); // εξάγουμε το τμήμα που ξεκινά από τη θέση 6 μέχρι τη θέση 12
System.out.println(s1.split(" "));
System.out.println(String.join(" + ", "1", "2", "3"));
System.out.println(s2.trim()); // αποκόπτει κενά μπρος και πίσω από το αλφαριθμητικό
System.out.println(s2.charAt(0)); // επιστρέφει τον 1ο χαρακτήρα του αλφαριθμητικού s2
System.out.println(s1.replace("εσπ", "ημ")); // Προσοχή! Δεν αντικαθιστά το s1, αλλά επιστρέφει ένα νέο αλφαριθμητικό
System.out.println(s1);
String s3 = s1.replace("εσπ", "ημ"); // επιστρέφει ένα νέο αλφαριθμητικό
System.out.println(s3);
System.out.println(s2.endsWith("ες"));
System.out.println(String.valueOf(0b100));
System.out.println(Integer.toString(0b100));
String empty = "";
String quotedStr = "\"";
String multilineStr= "Σε γνωρίζω από την κόψη\n του σπαθιού την τρομερή";
System.out.println(multilineStr);
s1 = "Γιάννης";
s2 = "Γιάννης";
System.out.println("s1 == s2? " + (s1 == s2));
s3 = new String("Γιάννης");
System.out.println("s1 == s3? " + (s1 == s3));
System.out.println("s2 == s3? " + (s2 == s3));
System.out.println("s1.equals(s3)? " + s1.equals(s3));
String s = "Hello \"Kosta\"";
System.out.println(s);
String html = "<html>\n" +
" <body>\n" +
" <p>Hello, world</p>\n" +
" </body>\n" +
"</html>";
System.out.println(html);
html = """
<html>
<body>
<p>Hello, world</p>
</body>
</html>
""";
System.out.println(html);
}
}</sandbox-source>
</sandbox>
</div>
<script src="https://javaalmanac.io/app/sandbox-bundle.js"></script>
<script>new Vue({ el: '#content' })</script>
</body>
</html>