Java J2EE Question and Answers

9. Can we use String in switch case?
  Java 7 extended the capability of switch case to use Strings also, earlier versions doesn't support this.
 
Your Name Your Email-ID
Your Answer
10. Write a function to find out longest palindrome in a given string?
  A String can contains palindrome strings in it and to find longest palindrome in given String is a programming question.
 
Your Name Your Email-ID
Your Answer
11. How to convert String to byte array and vice versa?
  We can use String getBytes() method to convert String to byte array and we can use String constructor new String(byte[] arr) to convert byte array to String.
 
Your Name Your Email-ID
Your Answer
12. Why String is popular HashMap key in Java?
 
  • Since String is immutable, its hashcode is cached at the time of creation and it doesn't need to be calculated again.
  • This makes it a great candidate for key in a Map and its processing is fast than other HashMap key objects.
  • This is why String is mostly used Object as HashMap Keys.
 
Your Name Your Email-ID
Your Answer
12345 Page 3 of 5