karthikeya Boyini

karthikeya Boyini

1,421 Articles Published

Articles by karthikeya Boyini

Page 58 of 143

How to get the Checksum of a Byte Array in Java?

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

Create a Byte Array for which you want the Checksum −byte[] arr = "This is it!".getBytes();Now, create a Checksum object −Checksum checksum = new Adler32(); checksum.update(arr, 0, arr.length);The update() above updates the current checksum with the specified array of bytes.Now, get the checksum with getValue() method, which gives the current checksum value.Exampleimport java.util.zip.Adler32; import java.util.zip.Checksum; public class Demo {    public static void main(String[] argv) throws Exception {       byte[] arr = "This is it!".getBytes();       Checksum checksum = new Adler32();       checksum.update(arr, 0, arr.length);       long res = checksum.getValue();     ...

Read More

CharBuffer put() method in Java

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

The required value can be written at the current position of the buffer and then the current position is incremented using the method put() in the class java.nio.CharBuffer. This method requires a single parameter i.e. the value to be written in the buffer and it returns the buffer in which the value is inserted.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);       ...

Read More

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 291 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
Showing 571–580 of 1,421 articles
« Prev 1 56 57 58 59 60 143 Next »
Advertisements