Survey
* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project
SDJ INFOSOFT PVT LTD
JAVA TEST-5
www.javapadho.com
Topice : String,StringBuffer,StringBuilder
1. String objects are immutable. True/false?
2. String object is used to represent multiple characters. True/false
3. String objects are more convenient to customize multiple charectors than char array. True/ false?
4. String class is a sub class to Object class. True/false?
5. String class is in java.lang package. True/false?
6. String class toString() method is returning content of String object. True/false?
7. String class equals() method is using == operator to compare two String objects. True/false?
8. String class hashCode() method is overrided. True/false?
9. String literals are storing in the constant pool. True/false?
10. Is it possible to create a String object from char array?
11. Is it possible to convert primitives to String objects?
12. public class Manager{
public static void main(String args[]){
String s1 = "too long";
System.out.println(s1.trim().trim().trim(). trim().length());
}
}
13. public class Manager{
public static void main(String args[]){
String s1 = "too long";
System.out.println(s1.trim().trim().concat("too short").trim().replace("too", "2").trim().length());
}
}
14. public class Manager{
public static void main(String args[]){
String s1 = "---abc 123-hello---";
System.out.println(s1.trim().trim().concat(" ").trim().replace("-", "").trim().length());
}
}
15. public class Manager{
public static void main(String args[]){
String s1 = "---abc 123-hello---";
s1.replace("-", " ");
s1.trim();
System.out.println(s1.length());
}
}
16. public class Manager{
public static void main(String args[]){
String s1 = new String(new char[]{'1','1','1'});
System.out.println(s1.replace("1", " ").trim().length());
}
}
17. public class Manager{
public static void main(String args[]){
String s1 = new String('1');
System.out.println(s1.replace("1", " ").trim().length());
}
}
18. public class Manager{
public static void main(String args[]){
String url = "http://sdjinfosoft.com";
System.out.println(url.indexOf('//') == url.lastIndexOf('//'));
} }
J2SE/J2EE/HADOOP/SUMMER TRAINING, 86/26 PRATAP NAGAR NEAR KUMBHA MARGH. M: 0141-2790887
www.javapadho.com Page 1
SDJ INFOSOFT PVT LTD
JAVA TEST-5
www.javapadho.com
Topice : String,StringBuffer,StringBuilder
19. public class Manager{
public static void main(String args[]){
String letters = "a,b,c,d,e,f";
System.out.println(letters.split(",", 2)[0]);
} }
20. public class Manager{
public static void main(String args[]){
String s1 = "";
s1.replace("", "new").concat("onceAgainNew").replace("n", "not").substring(3);
System.out.println(s1);
} }
21. public class Manager{
public static void main(String args[]){
StringBuffer sb = new StringBuffer("abc");
System.out.println(sb.equals("abc"));
} }
22. public class Manager{
public static void main(String args[]){
StringBuffer sb = new StringBuffer("abc");
System.out.println(sb.concat("abc"));
} }
23. public class Manager{
public static void main(String args[]){
StringBuffer sb = new StringBuffer("abc");
StringBuffer sb1 = new StringBuffer("abc");
System.out.println(sb.equals(sb1));
} }
24. public class Manager{
public static void main(String args[]){
StringBuffer sb = new StringBuffer("abc");
sb.append("cba").replace(0, 2, "c").substring(0, 4).reverse();
System.out.println(sb);
}
}
25. public class Manager{
public static void main(String args[]){
StringBuffer sb = new StringBuilder("abc");
sb.append("cba");
System.out.println(sb);
}
}
26. public class Manager{
public static void main(String args[]){
StringBuilder sb = new StringBuffer();
sb.append("123");
System.out.println(sb.toString().length() == 3);
}
}
27. public class Manager{
public static void main(String args[]){
StringBuilder sb = new StringBuilder();
System.out.println(sb.append("-123-").replace("-", " ").trimToSize());
J2SE/J2EE/HADOOP/SUMMER TRAINING, 86/26 PRATAP NAGAR NEAR KUMBHA MARGH. M: 0141-2790887
www.javapadho.com Page 2
SDJ INFOSOFT PVT LTD
JAVA TEST-5
www.javapadho.com
Topice : String,StringBuffer,StringBuilder
}
}
28. public class Manager{
public static void main(String args[]){
StringBuilder sb = new StringBuilder("[email protected]");
sb.replace(sb.indexOf("."), sb.length(), ".com");
System.out.println(sb);
}
}
29. public class Manager{
public static void main(String args[]){
StringBuffer s1 = new StringBuffer("100");
int i = Integer.parseInt(s1);
System.out.println(Math.sqrt(i) == 10);
}
}
30. public class Manager{
public static void main(String args[]){
StringBuffer s1 = new StringBuffer(new String(new String("123")).concat("123"));
System.out.println(s1 == "123123123");
}
}
31. public class Manager{
public static void main(String args[]){
String s1 = new String(new StringBuffer("123"));
System.out.println(s1 == "123");
}
}
32. public class Manager1 {
public static void main(String[] args) {
Integer intObj = new Integer("10002a");
}
}
33. public class Manager1 {
public static void main(String[] args) {
String s1 = null;
System.out.println(s1.length());
}
}
34. public class Manager1 {
public static void main(String[] args) {
int i = 9;
i = i/(i-9.0);
System.out.println(i);
}
}
35. public class Manager1 {
public static void main(String[] args) {
int i = 9;
i = i/(i-i);
J2SE/J2EE/HADOOP/SUMMER TRAINING, 86/26 PRATAP NAGAR NEAR KUMBHA MARGH. M: 0141-2790887
www.javapadho.com Page 3
SDJ INFOSOFT PVT LTD
JAVA TEST-5
www.javapadho.com
Topice : String,StringBuffer,StringBuilder
System.out.println(i);
}
}
36. public class Manager1 {
public static void main(String[] args) {
double d1 = 9;
int i = i/(9.0 - d1);
System.out.println(i);
}
}
String,StringBuffer,StringBuilder Ans:
1. true
2. true
3. true
4. true
5. true
6. true
7. false
8. true
9. true
10. Yes.
11.Yes
12. 8
13. 13
14. 13
15. 19
16. 0
17. CTE
18. CTE
19. a
20.
21. false
22. CTE
23. false
24. CTE
25. CTE
26. CTE
27. CTE
28. [email protected]
29. CTE
30. CTE
31. false
32. RTE (NumberFormatException)
33. RTE(NullPointerException)
34. CTE
35. RTE(ArithmaticException)
36. CTE
J2SE/J2EE/HADOOP/SUMMER TRAINING, 86/26 PRATAP NAGAR NEAR KUMBHA MARGH. M: 0141-2790887
www.javapadho.com Page 4