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. 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[]) {
String str = "we are what we repeatedly Do excellence, then, is not an act but a haBit";
for(String word:str.split(" ")){
if(word.startsWith("w")){
System.out.println(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[]) {
String str = "we are what we repeatedly Do excellence, then, is not an act but a haBit";
for(String word:str.split(" ")){
if(word.contains("ha")){
System.out.println(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[]) {
String str = "we are what we repeatedly Do excellence, then, is not an act but a haBit";
for(String word:str.split(" ")){
if(word.length() > 2 && word.charAt(2) == 'p'){
System.out.println(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[]) {
String str = "we are what we repeatedly Do excellence, then, is not an act but a haBit";
for(String word:str.split(" ")){
if(word.length() > 2 && word.endsWith("it")){
System.out.println(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[]) {
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> 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 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
Program should set the start and end index and then display this accordingly. For example the above pattern is for displayNumbersBetween(2,10) and following is for displayNumbersBetween(5,7)
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. 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. Optimizing Resource utilization. When you open a file using any programming language , that is actually a request to operating system to access the file. When such a request is made , resources are allocated by the OS. When you gracefully close those files, those resources are set free.
In Java if you don’t close the streams and files, Garbage collection identifies the open files which have lost the reference and hence will close them.
Help us improve. Please let us know the company, where you were asked this question :