Karthikeya Boyini has Published 2193 Articles

NavigableMap ceilingEntry() method in Java

karthikeya Boyini

karthikeya Boyini

Updated on 30-Jul-2019 22:30:24

111 Views

Use the NavigableMap ceilingEntry() method to returna key-value mapping associated with the least key greater than or equal to the given keyThe following is an example to implement ceilingEntry() method −Example Live Demoimport java.util.*; public class Demo { public static void main(String[] args) { ... Read More

Remove specified element from Java LinkedHashSet

karthikeya Boyini

karthikeya Boyini

Updated on 30-Jul-2019 22:30:24

767 Views

To remove a specified element from LinkedHashSet, use the remove() and include the element you want to remove as a parameter.First, set LinkedHashSet and add elements −LinkedHashSet hashSet = new LinkedHashSet(); hashSet.add(10); hashSet.add(20); hashSet.add(30); hashSet.add(40); hashSet.add(50); hashSet.add(60);Let us now remove an element −hashSet.remove(10);The following is an example to remove specified ... Read More

Remove all elements from Java LinkedHashSet

karthikeya Boyini

karthikeya Boyini

Updated on 30-Jul-2019 22:30:24

376 Views

To remove all the elements from LinkedHashSet in Java, use the clear() method.The following is an example to declare LinkedHashSet and add elements to it −LinkedHashSet hashSet = new LinkedHashSet(); hashSet.add(10); hashSet.add(20); hashSet.add(30); hashSet.add(40); hashSet.add(50); hashSet.add(60);Use the clear() method to remove all elements −hashSet.clear();The following is an example −Example Live Demoimport ... Read More

Get last entry from NavigableMap in Java

karthikeya Boyini

karthikeya Boyini

Updated on 30-Jul-2019 22:30:24

198 Views

To display the last entry from NavigableMap in Java, use the lastEntry() method.Let us first create NavigableMap.NavigableMap n = new TreeMap(); n.put("A", 498); n.put("B", 389); n.put("C", 868); n.put("D", 988); n.put("E", 686); n.put("F", 888); n.put("G", 999); n.put("H", 444); n.put("I", 555); n.put("J", 666);Get the last entry now.n.lastEntry()The following is an example to ... Read More

Fill elements in a Java double array in a specified range

karthikeya Boyini

karthikeya Boyini

Updated on 30-Jul-2019 22:30:24

324 Views

Elements can be filled in a Java double array in a specified range using the java.util.Arrays.fill() method. This method assigns the required double value in the specified range to the double array in Java.The parameters required for the Arrays.fill() method are the array name, the index of the first element ... Read More

How to use headSet() method of Java NavigableSet Class

karthikeya Boyini

karthikeya Boyini

Updated on 30-Jul-2019 22:30:24

120 Views

The headset() method returns elements up to a limit defined as a parameter.First, create a NavigableSet and add elements −NavigableSet set = new TreeSet(); set.add(10); set.add(25); set.add(40); set.add(55); set.add(70); set.add(85); set.add(100);Now, use the headset() method −set.headSet(55));The following is an example −Example Live Demoimport java.util.NavigableSet; import java.util.TreeSet; public class Demo {   ... Read More

Copy all elements of Java LinkedHashSet to an Object Array

karthikeya Boyini

karthikeya Boyini

Updated on 30-Jul-2019 22:30:24

214 Views

First, create a LinkedHashSet and add elements −LinkedHashSet l = new LinkedHashSet(); l.add(new String("1")); l.add(new String("2")); l.add(new String("3")); l.add(new String("4")); l.add(new String("5")); l.add(new String("6")); l.add(new String("7"));Now, copy it to an object array like this −// copying Object[] arr = l.toArray();The following is an example to copy all elements of a ... Read More

Create a new ArrayList from another collection in Java

karthikeya Boyini

karthikeya Boyini

Updated on 30-Jul-2019 22:30:24

395 Views

An ArrayList can be created from another collection using the java.util.Arrays.asList() method. A program that demonstrates this is given as follows −Example Live Demoimport java.util.ArrayList; import java.util.Arrays; import java.util.List; public class Demo {    public static void main(String args[]) throws Exception {       String str[] = { "John", "Macy", ... Read More

Fill elements in a Java long array in a specified range

karthikeya Boyini

karthikeya Boyini

Updated on 30-Jul-2019 22:30:24

172 Views

Elements can be filled in a Java long array in a specified range using the java.util.Arrays.fill() method. This method assigns the required long value in the specified range to the long array in Java.The parameters required for the Arrays.fill() method are the array name, the index of the first element ... Read More

Copy all elements in Java TreeSet to an Object Array

karthikeya Boyini

karthikeya Boyini

Updated on 30-Jul-2019 22:30:24

304 Views

Create a TreeSet and add elements −TreeSet tSet = new TreeSet(); tSet.add("TV"); tSet.add("Radio"); tSet.add("Internet");Now, let us copy it to object array −Object[] arr = tSet.toArray(); for (Object ob: arr) {    System.out.println(ob); }The following is an example to copy all elements in TreeSet to an Object Array −Example Live Demoimport java.util.*; ... Read More

Advertisements