karthikeya Boyini

karthikeya Boyini

1,421 Articles Published

Articles by karthikeya Boyini

Page 58 of 143

Get SubList from LinkedList in Java

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 1K+ Views

The subList of a LinkedList can be obtained using the java.util.LinkedList.subList(). This method takes two parameters i.e. the start index for the sub-list(inclusive) and the end index for the sub-list(exclusive) from the required LinkedList. If the start index and the end index are the same, then an empty sub-list is returned.A program that demonstrates this is given as follows −Exampleimport java.util.LinkedList; import java.util.List; public class Demo { public static void main(String[] args) { LinkedList l = new LinkedList(); l.add("John"); ...

Read More

Java Program to strip a filename of its extension after the last dot

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 4K+ Views

The method removeExtension() is used to strip a filename of its extension after the last dot. This method requires a single parameter i.e. the file name and it returns the file name without its extension.A program that demonstrates this is given as follows −Exampleimport java.io.File; public class Demo {    public static String removeExtension(String fname) {       int pos = fname.lastIndexOf('.');       if(pos > -1)          return fname.substring(0, pos);       else          return fname;    }    public static void main(String[] args) {       System.out.println(removeExtension("c:\JavaProgram\demo1.txt"));   ...

Read More

Check the frequency of an element in Java with Collections.frequency

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 290 Views

Create a List in Java −List< String >list = Arrays.asList("P", "Q", "R", "P", "T", "P", "U", "V", "W", "X", "W" );Now, let’s say you want to get the frequency of element P. For that, use the Collections.frequency() method −Collections.frequency(list, "P");A shown above, we can find the occurrence of any letter as well −Collections.frequency(list, "T");Exampleimport java.util.Arrays; import java.util.Collections; import java.util.List; public class Demo {    public static void main(String[] args) {       Listlist = Arrays.asList("P", "Q", "R", "P", "T", "P", "U", "V", "W", "X", "W" );       int checkOccurrence = Collections.frequency(list, "P");       System.out.println("Occurrence of ...

Read More

Get the Current Working Directory in Java

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 8K+ Views

The method java.lang.System.getProperty() is used to obtain the system property. This system property is specified by the key which is the parameter for the method. To obtain the current working directory, the key used is user.dir.A program that demonstrates this is given as follows −Examplepublic class Demo {    public static void main(String[] argv) throws Exception {       String currentDirectory = System.getProperty("user.dir");       System.out.println("The current working directory is " + currentDirectory);    } }The output of the above program is as follows −OutputThe current working directory is c:\JavaProgramNow let us understand the above program.The current working ...

Read More

CharBuffer hasArray() method in Java

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 170 Views

It can be checked if a buffer has the backing of an accessible char array by using the method hasArray() in the class java.nio.CharBuffer. This method returns true if the buffer has the backing of an accessible int array and false otherwise.A program that demonstrates this is given as follows −Exampleimport java.nio.*; import java.util.*; public class Demo {    public static void main(String[] args) {       int n = 5;       try {          CharBuffer buffer = CharBuffer.allocate(5);          buffer.put('A');          buffer.put('P');          buffer.put('P'); ...

Read More

NavigableSet Class lower() method in Java

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 145 Views

The lower() method of NavigableSet returns the greatest element strictly less than the given element i.e. 35 here −lower(35);The following is an example to implement the lower() method in Java −Exampleimport java.util.NavigableSet; import java.util.TreeSet; public class Demo { public static void main(String[] args) { 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); System.out.println("Returned Value = " + set.lower(35)); } }OutputReturned Value = 25

Read More

Retrieve environment variables with Java Map Collection

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 530 Views

First, use the getenv() method to get the environment variables −System.out.println("PATH = " + System.getenv("PATH"));Now, get the key and value. Loop through to get the list of environment variables −Map e = System.getenv(); for (Iterator i = e.entrySet().iterator(); i.hasNext();) { Map.Entry mapEntry = (Map.Entry) i.next(); System.out.println(mapEntry.getKey() + " = " + mapEntry.getValue()); }The following is an example to retrieve environment variables with Map Collection −Exampleimport java.util.Iterator; import java.util.Map; public class Demo { public static void main(String args[]) { System.out.println("PATH = " + System.getenv("PATH")); ...

Read More

How to initialize a vector in C++?

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 1K+ Views

Initialization vector can be done in many ways1) Initialize a vector by push_back() methodAlgorithmBegin    Declare v of vector type.    Call push_back() function to insert values into vector v.    Print “Vector elements:”.    for (int a : v)       print all the elements of variable a. End.Example#include #include using namespace std; int main() {    vector v;    v.push_back(6);    v.push_back(7);    v.push_back(10);    v.push_back(12);    cout

Read More

Custom ArrayList in Java

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 1K+ Views

A custom ArrayList can have multiple types of data and its attributes in general are based on the user requirements.A program that demonstrates a custom ArrayList is given as follows −Exampleimport java.util.ArrayList; public class CustomArrayList {    int n = 5;    class Employee {       int eno;       String name;       Employee(int eno, String name) {          this.eno = eno;          this.name = name;       }    }    public static void main(String args[]) {       int eno[] = {101, 102, 103, 104, ...

Read More

How to create Java Priority Queue to ignore duplicates?

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 1K+ Views

The simplest way to create a Java Priority Queue to ignore duplicates is to first create a Set implementation −HashSet set = new HashSet (); set.add(100); set.add(150); set.add(250); set.add(300); set.add(250); set.add(500); set.add(600); set.add(500); set.add(900);Now, create Priority Queue and include the set to remove duplicates in the above set −PriorityQueuequeue = new PriorityQueue(set);Exampleimport java.util.HashSet; import java.util.PriorityQueue; public class Demo {    public static void main(String[] args) {       HashSetset = new HashSet();       set.add(100);       set.add(150);       set.add(250);       set.add(300);       set.add(250);       set.add(500);   ...

Read More
Showing 571–580 of 1,421 articles
« Prev 1 56 57 58 59 60 143 Next »
Advertisements