Core java - Interview Questions and Answers for 'Datametica' - 3 question(s) found - Order By Newest Very frequently asked. Favorite question in Walk in Drive of many Indian service companies. Q1. Difference between TreeMap and HashMap ? Core Java
Ans. They are different the way their elements are stored in memory. TreeMap stores the Keys in order whereas HashMap stores the key value pairs randomly. Sample Code for treemap Sample Code for hashmap Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   collections   map   treemap   hashmap   treemap vs hashmap Asked in 31 Companies basic   frequent Try 1 Question(s) TestRelated Questions What is comparator interface used for ? Which of the following collections stores its elements in insertion Order ?
a. HashMap
b. TreeMap
c. LinkedHashMap
d. LinkedMap Which are the sorted collections ? Which of the following collection maintain its elements in Natural Sorted order ? How can we reverse the order in the TreeMap ? TreeMap orders the elements on which field ? How TreeMap orders the elements if the Key is a String ? Can we add heterogeneous elements into TreeMap ? Will it create any problem if We add elements with key as user defined object into the TreeMap ? Q2. Write a Program to check if 2 strings are Anagrams ? Core Java
Ans. public void checkIfAnagram(String str1,String str2){
boolean anagram = true;
for(char c:str1.toCharArray()){
if(!str2.contains(String.valueOf(c))){
System.out.println("Strings are Anagrams");
anagram = false;
}
if(anagram == true){
System.out.println("Strings are not Anagrams");
}
}
} Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve   check if 2 strings are Anagrams Asked in 30 Companies basic   frequent Related Questions Difference between == and .equals() ? Why is String immutable in Java ? Explain the scenerios to choose between String , StringBuilder and StringBuffer ?
or
What is the difference between String , StringBuilder and StringBuffer ? What are the difference between composition and inheritance in Java? Explain OOPs
or
Explain OOPs Principles
or
Explain OOPs Concepts
or
Explain OOPs features
or
Tell me something about OOPs What is a Lambda Expression ? What's its use ? What are different ways to create String Object? Explain. Why Char array is preferred over String for storing password? Does garbage collection guarantee that a program will not run out of memory? What is the difference between final, finally and finalize() ? Ans. A static initialization block is a normal block of code enclosed in braces, { }, and preceded by the static keyword. Here is an example:
static {
// whatever code is needed for initialization goes here
}
A class can have any number of static initialization blocks, and they can appear anywhere in the class body. The runtime system guarantees that static initialization blocks are called in the order that they appear in the source code. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   oops   static   static block Asked in 16 Companies basic   frequent Related Questions How can we run a java program without making any object? How can we create objects if we make the constructor private ? Similarity and Difference between static block and static method ? Will the static block be executed in the following code ? Why ? Is it possible to compile and run a Java program without writing main( ) method? Will static block for Test Class execute in the following code ? Can we initialize member variables within static block ? How can we execute a Java class independently if it doesn't have a static main method ? Can we create object in static block ?