Skip to content

Commit

Permalink
Day 1 break 4
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonHGR committed May 8, 2023
1 parent 5f1b45a commit fda0ec2
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 1 deletion.
Binary file added Capture 3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Capture 4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Capture 5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 42 additions & 1 deletion Questions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,45 @@ A) Compilation fails
B) Exception at runtime
C) -1
D) 0x00000005
E) 5
E) 5

Q) Which print "true"
A) String s = "Hello";
String t = "He";
t += "llo";
sout(s == t);

B) String s = "Hello";
String t = "He";
t += "llo";
sout(s.equals(t));

C) StringBuilder s = new StringBuilder("Hello");
StringBuilder t = new StringBuilder("He");
t.append("llo");
sout(s.equals(t));

D) List<String> ls = List.of("Fred", "Jim");
List<String> ls2 = new ArrayList<>(ls);
sout(ls.equals(ls2));

E) LocalDate ld = LocalDate.of(2021, 3, 29);
LocalDate ld2 = LocalDate.of(2021, 3, 29);
sout(ld.equals(ld2));

Q) Which are true?

String s1 = "Hello";
String s2 = new StringBuilder("Hello").toString();
String s3 = s2.intern();

and, in another jarfile:
class X {
static String h = "Hel" + "lo";
}

A) s1 == s2
B) s2 == s3
C) s1 == s3
D) X.h == s1
E) None of the above
13 changes: 13 additions & 0 deletions src/main/java/intern/Question.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package intern;

public class Question {
public static void main(String[] args) {
String s1 = "hel" + "lo";
String s3 = "hello";
String s4 = s3.toLowerCase();
String s2 = "hello".concat("");
System.out.println(s1==s2);
System.out.println(s1==s3);
System.out.println(s1==s4);
}
}

0 comments on commit fda0ec2

Please sign in to comment.