More than 3000 questions in repository. There are more than 900 unanswered questions. Click here and help us by providing the answer. Have a video suggestion. Click Correct / Improve and please let us know.
Ans. Yes, they both aim at providing synchronized access to the Map collection. The only difference is in their implementation. ConcurrentHashMap came after HashTable and hence technically more efficient as it doesn't lock the complete map while accessing it.
Help us improve. Please let us know the company, where you were asked this question :
Ans. HashTable locks the complete collection to provide synchronization whereas ConcurrentHashMap only locks segments to achieve synchronization and hence better efficient and faster.
Help us improve. Please let us know the company, where you were asked this question :
Ans. public class BuggyBread {
public static void main(String args[]) {
String str = "we are what we repeatedly do excellence then is not an act but a haBit";
Set<String> wordSet = new TreeSet(); // Using Linked Hash Set as we would like to retrieve words in the insertion order
Ans.
public class BuggyBread {
public static void main(String args[]) {
String str = "we are what we repeatedly Do excellence, then, is not an act but a haBit";
Set<String> wordSet = new LinkedHashSet(); // Using Linked Hash Set as we would like to retrieve words in the insertion order
Ans. public class BuggyBread {
public static void main(String args[]) {
String str1 = "we are what we repeatedly Do excellence, then, is not an act but a haBit";
String str2 = "we are what we repeatedly Do is";
String[] str1Words = str1.split(" ");
String[] str2Words = str2.split(" ");
Ans. public class BuggyBread {
public static void main(String args[]) {
String str1 = "we are what we repeatedly Do excellence, then, is not an act but a haBit";
String str2 = "we are what we repeatedly Do is";
String[] str1Words = str1.split(" ");
String[] str2Words = str2.split(" ");
Ans. public class BuggyBread {
public static void main(String args[]) {
String str = "we are what we repeatedly Do excellence, then, is not an act but a haBit";
Set<String> words = new HashSet();
for(String word:str.split(" ")){
if(words.contains(word)){
System.out.println(word);
} else {
words.add(word);
}
}
}
}
Help us improve. Please let us know the company, where you were asked this question :
Ans. public class BuggyBread{
public static void main (String args[]) {
Set<Character> set = new HashSet();
Set<Character> setWithDuplicateChar = new HashSet();
String str = "hello world";
for(char character: str.toCharArray()){
if(set.contains(character)){
setWithDuplicateChar.add(character);
} else {
set.add(character);
}
}
System.out.println(setWithDuplicateChar);
}
}
Help us improve. Please let us know the company, where you were asked this question :
Q1461. Write a program to print all even numbers first and then all odd numbers till 100. For example the output should be
2
4
6
8
...... 100
and then
1
3
5
7
...... 99
using only 1 for loop ? Is it possible with just one loop ?
public class BuggyBread{
public static void main (String args[]) {
int x = 50;
for(int i=1;i <= 100;i++){
if(i<=50){
System.out.println(i*2);
} else {
System.out.println(i-x);
x = x - 1;
}
}
}
}
Help us improve. Please let us know the company, where you were asked this question :
Q1462. Write a program in Java that prints the numbers from 1 to 100. But for multiples of three print Fizz instead of the number and for the multiples of five print Buz. For numbers which are multiples of both three and five print FizzBuzz
Q1463. Write a Program to check if string is a Colidrome ?
(Colidrome is a word that has n alphabets followed by the reverse of the n alphabets, for ex - mallom)
Ans.
public class Class {
public static void main(String[] args) {
String str = "mallam";
String firstHalf = str.substring(0, str.length() / 2);
String secondHalf = str.substring(str.length() / 2);
if (firstHalf.equals(new StringBuilder(secondHalf).reverse().toString())) {
System.out.println("It's a Colidrome");
} else {
System.out.println("It's not a Colidrome");
}
}
}
Help us improve. Please let us know the company, where you were asked this question :
Ans. public class Class{
public static void main(String[] args){
String string1 = "Hello I am Jack. I live in United States. I live in california state.";
String string2 = "I live in";
int startIndex = 0;
int endIndex = string1.length()-1;
Ans. public class Class{
public static void main(String[] args){
String string1 = "Hello I am Jack. I live in United States. I live in california state.";
String string2 = "I live in";
if(string1.indexOf(string2) >= -1){
System.out.println("string2 is sub string of string1");
} else {
System.out.println("string2 is not sub string of string1");
}
}
}
Help us improve. Please let us know the company, where you were asked this question :
Ans. public class Class{
public static void main(String[] args){
List<Integer> collector = new ArrayList();
Scanner scanner = new Scanner(System.in);
int x = scanner.nextInt();
while(x != 0){
collector.add(x);
x = scanner.nextInt();
}
System.out.println(collector.stream().collect(Collectors.averagingInt(p->((Integer)p))));
}
}
Help us improve. Please let us know the company, where you were asked this question :
Ans. Compilation is the process of converting Java source files to class files which can be executed by the Java runtime environment whereas Decompilation is the process of converting class files back to the Java Source code.
Help us improve. Please let us know the company, where you were asked this question :