(base) MAC:Thu Oct 15:13:26:4240> jshell | Welcome to JShell -- Version 14.0.1 | For an introduction type: /help intro jshell> /open Foo.java jshell> Foo f = new Foo(); f ==> Foo@31cefde0 jshell> foo.hashCode() | Error: | cannot find symbol | symbol: variable foo | foo.hashCode() | ^-^ jshell> f.hashCode() $3 ==> 835648992 jshell> Integer.toString(f, 16) | Error: | incompatible types: Foo cannot be converted to int | Integer.toString(f, 16) | ^ jshell> Integer.toString(f.hashCode(), 16) $4 ==> "31cefde0" jshell> "a".hashCode() $5 ==> 97 jshell> "b".hashCode() $6 ==> 98 jshell> "c".hashCode() $7 ==> 99 jshell> "aa".hashCode() $8 ==> 3104 jshell> "ab".hashCode() $9 ==> 3105 jshell> String s = "abcdefghijklnmopABCDEFGHIJKLMNOP" s ==> "abcdefghijklnmopABCDEFGHIJKLMNOP" jshell> "some" + "thing" $11 ==> "something" jshell> "some"*50 | Error: | bad operand types for binary operator '*' | first type: java.lang.String | second type: int | "some"*50 | ^-------^ jshell> "some".repeat(50) $12 ==> "somesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesome" jshell> "some".repeat(-4) | Exception java.lang.IllegalArgumentException: count is negative: -4 | at String.repeat (String.java:3586) | at (#13:1) jshell> s[0] | Error: | array required, but java.lang.String found | s[0] | ^--^ jshell> s.charAt(0) $14 ==> 'a' jshell> (int) s.charAt(0) $15 ==> 97 jshell> "a".compareTo("c") $16 ==> -2 jshell> "a".compareTo("c") < 0 $17 ==> true jshell> "a".compareTo("A") < 0 $18 ==> false jshell> "abby".compareTo("acid") $19 ==> -1 jshell> "abby".compareTo("acid") < 0 $20 ==> true jshell> "a".compareToIgnoreCase("A") $21 ==> 0 jshell> "a".compareToIgnoreCase("A") > 0 $22 ==> false jshell> // "a" > "A" jshell> "some".concat("thing") $23 ==> "something" jshell> s.contains("cdef") $24 ==> true jshell> s s ==> "abcdefghijklnmopABCDEFGHIJKLMNOP" jshell> // "cdef" in s jshell> file = "quack.html" | Error: | cannot find symbol | symbol: variable file | file = "quack.html" | ^--^ jshell> String file = "quack.html" file ==> "quack.html" jshell> file.endWith(".html") | Error: | cannot find symbol | symbol: method endWith(java.lang.String) | file.endWith(".html") | ^----------^ jshell> file.endsWith(".html") $27 ==> true jshell> file.startWith("quack") | Error: | cannot find symbol | symbol: method startWith(java.lang.String) | file.startWith("quack") | ^------------^ jshell> file.startsWith("quack") $28 ==> true jshell> String a = "aardvark" a ==> "aardvark" jshell> String b = "aardvark" b ==> "aardvark" jshell> a.equals(b) $31 ==> true jshell> a == b $32 ==> true jshell> c = new String("aardvark") | Error: | cannot find symbol | symbol: variable c | c = new String("aardvark") | ^ jshell> String c = new String("aardvark") c ==> "aardvark" jshell> c == b $34 ==> false jshell> "ABC".equalsIgnoreCase("abc") $35 ==> true jshell> String.format("%s is eating %s in %s", "Chloe", "pizza", "PFM") $36 ==> "Chloe is eating pizza in PFM" jshell> String.format(".6f", 22.0/7) $37 ==> ".6f" jshell> String.format("%.6f", 22.0/7) $38 ==> "3.142857" jshell> String.format(5.2, 54.0/14); | Error: | no suitable method found for format(double,double) | method java.lang.String.format(java.lang.String,java.lang.Object...) is not applicable | (argument mismatch; double cannot be converted to java.lang.String) | method java.lang.String.format(java.util.Locale,java.lang.String,java.lang.Object...) is not applicable | (argument mismatch; double cannot be converted to java.util.Locale) | String.format(5.2, 54.0/14); | ^-----------^ jshell> String.format("%5.2f", 54.0/14); $39 ==> " 3.86" jshell> String.format("%5.2f%%", 54.0/14); $40 ==> " 3.86%" jshell> s s ==> "abcdefghijklnmopABCDEFGHIJKLMNOP" jshell> s.indexOf('l') $42 ==> 11 jshell> s.indexOf('l', 13) $43 ==> -1 jshell> s.indexOf("klmn") $44 ==> -1 jshell> s.indexOf("bcd") $45 ==> 1 jshell> s.indexOf("bcd", 5) $46 ==> -1 jshell> // indexOf in Py is find jshell> s.lastIndexOf("bcd") $47 ==> 1 jshell> //lastIndexOf is Py's rfind jshell> s = " \t\t\n\n " s ==> " \t\t\n\n " jshell> s.isBlank() $49 ==> true jshell> s.strip().length() == 0 $50 ==> true jshell> s.isEmpty() $51 ==> false jshell> s s ==> " \t\t\n\n " jshell> print(s) | Error: | cannot find symbol | symbol: method print(java.lang.String) | print(s) | ^---^ jshell> System.out.println(s) jshell> s.length() $54 ==> 12 jshell> String q = "this and that" q ==> "this and that" jshell> q.replace('n', 'N') $56 ==> "this aNd that" jshell> q.replace("h", "HELLO") $57 ==> "tHELLOis and tHELLOat" jshell> q q ==> "this and that" jshell> String paddy = " space " paddy ==> " space " jshell> paddy.strip() $60 ==> "space" jshell> paddy.stripLeading() $61 ==> "space " jshell> paddy.stripTrailing() $62 ==> " space" jshell> // strip, lstrip, rstrip jshell> q q ==> "this and that" jshell> q[5:] | Error: | ']' expected | q[5:] | ^ jshell> q.substring(5) $64 ==> "and that" jshell> q.substring(0,5) $65 ==> "this " jshell> q.substring(3,5) $66 ==> "s " jshell> String.valueOf(true) $67 ==> "true" jshell> String.valueOf(5) $68 ==> "5" jshell> String.valueOf(23532) $69 ==> "23532" jshell> String.valueOf(6.02e23) $70 ==> "6.02E23" jshell> byte b = 42; b ==> 42 jshell> String.valueOf(b) $72 ==> "42" jshell> Object o = new Object(); o ==> java.lang.Object@470e2030 jshell> String.value(o) | Error: | method value in class java.lang.String cannot be applied to given types; | required: no arguments | found: java.lang.Object | reason: actual and formal argument lists differ in length | String.value(o) | ^----------^ jshell> String.valueOf(o) $74 ==> "java.lang.Object@470e2030" jshell> ArrayList al = new ArrayList<>(); al ==> [] jshell> al.add("aardvark"); $76 ==> true jshell> al.add("bat"); $77 ==> true jshell> al.add("cougar"); $78 ==> true jshell> al.add("dog | Error: | unclosed string literal | al.add("dog | ^ jshell> al.add("dog"); $79 ==> true jshell> al al ==> [aardvark, bat, cougar, dog] jshell> al[0] | Error: | array required, but java.util.ArrayList found | al[0] | ^---^ jshell> al.get(0) $81 ==> "aardvark" jshell> al.get(3) $82 ==> "dog" jshell> al.get(4) | Exception java.lang.IndexOutOfBoundsException: Index 4 out of bounds for length 4 | at Preconditions.outOfBounds (Preconditions.java:64) | at Preconditions.outOfBoundsCheckIndex (Preconditions.java:70) | at Preconditions.checkIndex (Preconditions.java:248) | at Objects.checkIndex (Objects.java:373) | at ArrayList.get (ArrayList.java:426) | at (#83:1) jshell> al.size() $84 ==> 4 jshell> al al ==> [aardvark, bat, cougar, dog] jshell> al.add(1, "aardwolf"); jshell> al al ==> [aardvark, aardwolf, bat, cougar, dog] jshell> al.append("elephant"); | Error: | cannot find symbol | symbol: method append(java.lang.String) | al.append("elephant"); | ^-------^ jshell> al.add("elephant"); $88 ==> true jshell> al al ==> [aardvark, aardwolf, bat, cougar, dog, elephant] jshell> al al ==> [aardvark, aardwolf, bat, cougar, dog, elephant] jshell>