- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Nancy Den has Published 330 Articles
![Nancy Den](https://www.tutorialspoint.com/assets/profiles/13557/profile/60_88439-1512714529.jpg)
Nancy Den
300 Views
To right align the text in a JComboBox, use the following:ComponentOrientation.RIGHT_TO_LEFTThe following is an example to right align the text in a ComboBox:Exampleimport java.awt.Component; import java.awt.ComponentOrientation; import javax.swing.DefaultListCellRenderer; import javax.swing.JComboBox; import javax.swing.JFrame; import javax.swing.JList; public class SwingDemo extends JFrame { public SwingDemo() { JComboBox combo = ... Read More
![Nancy Den](https://www.tutorialspoint.com/assets/profiles/13557/profile/60_88439-1512714529.jpg)
Nancy Den
254 Views
For JCheckBox, use the following to set tooltip text:checkBox1.setToolTipText("Sports Football"); checkBox2.setToolTipText("Sports Tennis");Tooltip text is visible whenever you will place cursor on that particular text.The following is an example. Here, we have set the tooltip text for both the sports:Exampleimport java.awt.*; import java.awt.event.*; import javax.swing.*; public class SwingDemo { private ... Read More
![Nancy Den](https://www.tutorialspoint.com/assets/profiles/13557/profile/60_88439-1512714529.jpg)
Nancy Den
565 Views
To display the first element in a JComboBox, use the getSelectedIndex():comboBox.setSelectedIndex(0);The following is an example to display the first element in a JComboBox in Java:Exampleimport java.awt.BorderLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JTextArea; public class SwingDemo { public static void main(String[] args) ... Read More
![Nancy Den](https://www.tutorialspoint.com/assets/profiles/13557/profile/60_88439-1512714529.jpg)
Nancy Den
207 Views
Let us first create a Stream:Stream stream = Stream.of("Bing Bang Theory", "Vampire Diaries", "Game of Thrones", "Homecoming");Now convert the above stream to typed array:final String[] strArr = stream.toArray(String[]::new);The following is an example to convert Stream to typed array in Java:Exampleimport java.util.Arrays; import java.util.stream.Stream; public class Demo { public static ... Read More
![Nancy Den](https://www.tutorialspoint.com/assets/profiles/13557/profile/60_88439-1512714529.jpg)
Nancy Den
411 Views
Let us create string Stream:Stream stream = Stream.of("Bing Bang Theory", "Vampire Diaries", "Game of Thrones", "Homecoming");Convert the above string stream and join them with Collectors:final String str = stream.collect(Collectors.joining(" "));The following is an example to convert string Stream to join them:Exampleimport java.util.stream.Collectors; import java.util.stream.Stream; public class Demo { public ... Read More
![Nancy Den](https://www.tutorialspoint.com/assets/profiles/13557/profile/60_88439-1512714529.jpg)
Nancy Den
762 Views
Let us first create a Stream:Stream stream = Stream.of("UK", "US", "India", "Australia", "Armenia", "Canada", "Poland");Now convert Stream to TreeSet:Set set = stream.collect(Collectors.toCollection(TreeSet::new));The following is an example to convert String to TreeSet in Java:Exampleimport java.util.Set; import java.util.TreeSet; import java.util.stream.Collectors; import java.util.stream.Stream; public class Demo { public static void main(String[] args) ... Read More
![Nancy Den](https://www.tutorialspoint.com/assets/profiles/13557/profile/60_88439-1512714529.jpg)
Nancy Den
357 Views
Let’s say the following is the String List:List list = new ArrayList(); list.add("Tom"); list.add("John"); list.add("David"); list.add("Paul"); list.add("Gayle"); list.add("Narine"); list.add("Joseph");Now, let’s say you need to filter elements beginning with a specific letter. For that, use filter() and startsWith():long res = list .stream() .filter((s) -> s.startsWith("J")) .count();We have also ... Read More
![Nancy Den](https://www.tutorialspoint.com/assets/profiles/13557/profile/60_88439-1512714529.jpg)
Nancy Den
752 Views
Let’s say we have a String List with an empty value. Here, we have empty array elements before Football and after Squash:List sports = Arrays.asList("", "Football", "Cricket", "Tennis", "Squash", "", "Fencing", "Rugby");Now filter the empty string values. At first, we have used Predicate to negate values:Stream stream = sports.stream(); Predicate ... Read More
![Nancy Den](https://www.tutorialspoint.com/assets/profiles/13557/profile/60_88439-1512714529.jpg)
Nancy Den
2K+ Views
Let’s say the following is our List with string elements:List leagues = Arrays.asList("BBL", "IPL", "MLB", "FPL", "NBA", "NFL");Now, create a stream and filter elements that end with a specific letter:Stream stream = leagues.stream().filter(leagueName -> leagueName.endsWith("L"));Now, use Objects::nonnull for non-null values:List list = stream.filter(Objects::nonNull).collect(Collectors.toList());The following is an example to filter non-null ... Read More
![Nancy Den](https://www.tutorialspoint.com/assets/profiles/13557/profile/60_88439-1512714529.jpg)
Nancy Den
2K+ Views
You can easily query MongoDB with “like”:db.yourCollectionName.find({"yourFieldName" : /.*yourMatchingValue.*/}).pretty();To understand the above syntax, let us create a collection with some documents. Here, we have a collection with the name ‘employee’. The query is as follows:> db.employee.insert({"EmployeeName":"John", "EmployeeSalary":450000}); WriteResult({ "nInserted" : 1 }) > db.employee.insert({"EmployeeName":"Carol", "EmployeeSalary":150000}); WriteResult({ "nInserted" : 1 }) ... Read More