Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- String str = "Hello";
- for(int i=0; i < str.length(); i++){
- System.out.println(str.charAt(i));
- }
- /////////////////////////////////////////////////////////////////////////////////////////////////
- String str = "SoftUni";
- System.out.println(str);
- for (int i = 0; i < str.length(); i++) {
- System.out.printf("str[%d] = %s\n", i, str.charAt(i));
- }
- System.out.println(str.indexOf("Uni")); // 4
- System.out.println(str.indexOf("uni")); // -1 (not found)
- System.out.println(str.substring(4, 7)); // Uni
- System.out.println(str.replace("Soft", "Hard")); // HardUni
- System.out.println(str.toLowerCase()); // softuni
- System.out.println(str.toUpperCase()); // SOFTUNI
- String firstName = "Steve";
- String lastName = "Jobs";
- int age = 56;
- System.out.println(firstName + " " + lastName +
- " (age: " + age + ")"); // Steve Jobs (age: 56)
- String allLangs = "C#, Java; HTML, . .. . . CSS; PHP, SQL";
- String[] langs = allLangs.split("[,. ;]+");
- for (String lang : langs) {
- System.out.println(lang);
- }
- System.out.println("Langs = " + String.join(", ", langs));
- System.out.println(" \n\n Software University \r ".trim());
- ////////////////////////////////////////////////////////////////////////////////////////
- String[] words = "yes yes".split(" ");
- System.out.println("words[0] = " + words[0]);
- System.out.println("words[1] = " + words[0]);
- System.out.println(words[0] == words[1]); // false
- System.out.println(words[0].equals(words[1])); // true
- if (words[0] == words[1]) {
- System.out.println("words[0] == words[1]");
- } else {
- System.out.println("words[0] != words[1]");
- }
- if (words[0] == "yes") {
- System.out.println("words[0] == yes");
- } else {
- System.out.println("words[0] != yes");
- }
- if (words[0].equals(words[1])) {
- System.out.println("words[0].equals(words[1])");
- }
- if (words[0].equals("yes")) {
- System.out.println("words[0].equals(\"yes\")");
- }
- System.out.println("Alice".compareTo("Mike")); // < 0
- System.out.println("Alice".compareTo("Alice")); // == 0
- System.out.println("Mike".compareTo("Alice")); // > 0
- if ("Alice".compareTo("Mike") < 0) {
- System.out.println("Alice < Mike");
- }
- if ("Alice".compareTo("Alice") == 0) {
- System.out.println("Alice == Alice");
- }
- if ("Mike".compareTo("Alice") > 0) {
- System.out.println("Mike > Alice");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement