Karthikeya Boyini has Published 2193 Articles

Java program to check the end of a string

karthikeya Boyini

karthikeya Boyini

Updated on 02-Aug-2024 18:17:40

3K+ Views

In general, the endswith() method in Java is used to check whether the given string ends with a specific suffix string or not. If the substring ends with the specific string then it will return a Boolean value true, otherwise it will return false if the value is not found. ... Read More

Java program to rename a file or directory

karthikeya Boyini

karthikeya Boyini

Updated on 02-Aug-2024 18:16:28

2K+ Views

The method File.renameTo() method of the java.io package is used to rename a file or directory. This method requires a single parameter i.e. the name that the file or directory is renamed to and it returns true on the success of the renaming or false otherwise. Syntax public boolean renameTo(File dest) ... Read More

Java program to remove items from Set

karthikeya Boyini

karthikeya Boyini

Updated on 31-Jul-2024 17:51:18

4K+ Views

A set in Java is modelled after the mathematical set and it cannot contain duplicate elements. The set interface contains the methods that are inherited from Collection. The method remove() removes the specified items from the set collection. A program that demonstrates the removal of items from Set using remove() ... Read More

Java program to delete duplicate characters from a given String

karthikeya Boyini

karthikeya Boyini

Updated on 31-Jul-2024 17:49:38

3K+ Views

The Set interface does not allow duplicate elements, therefore, create a set object and try to add each element to it using the add() method in case of repetition of elements this method returns false − If you try to add all the elements of the array to a Set, ... Read More

Java program to double the size of an array

karthikeya Boyini

karthikeya Boyini

Updated on 02-Jul-2024 11:21:24

4K+ Views

In this article, we will learn how to double the size of an array in Java. This involves creating a new array with twice the length of the original array and copying the elements from the original array to the new, larger array. Problem Statement Create an initial array with ... Read More

Java Program to convert boolean to integer

karthikeya Boyini

karthikeya Boyini

Updated on 25-Jun-2024 14:39:45

13K+ Views

To convert boolean to integer, let us first declare a variable of boolean primitive. boolean bool = true; Now, to convert it to integer, let us now take an integer variable and return a value “1” for “true” and “0” for “false”. int val = (bool) ? 1 : 0; ... Read More

Java Program to convert an integer into binary

karthikeya Boyini

karthikeya Boyini

Updated on 21-Jun-2024 13:59:18

13K+ Views

To convert an integer to binary, use the Integer.toBinaryString() method in Java.Let’s say the following is the integer we want to convert.int val = 999;Converting the above integer to binary.Integer.toBinaryString(val)Example Live Demopublic class Demo {     public static void main(String[] args) {        int val = 999;        // integer        System.out.println("Integer: "+val);     ... Read More

Java Program to locate a substring in a string

karthikeya Boyini

karthikeya Boyini

Updated on 18-Jun-2024 18:39:39

15K+ Views

To locate a substring in a string, use the indexOf() method.Let’s say the following is our string.String str = "testdemo";Find a substring ‘demo’ in a string and get the index.int index = str.indexOf( 'demo');Example Live Demopublic class Demo {    public static void main(String []args) {       String str ... Read More

Java Program to retrieve the set of all keys and values in HashMap

karthikeya Boyini

karthikeya Boyini

Updated on 18-Jun-2024 17:04:46

16K+ Views

To retrieve the set of keys from HashMap, use the keyset() method. However, for set of values, use the values() method.Create a HashMap −HashMap hm = new HashMap(); hm.put("Wallet", new Integer(700)); hm.put("Belt", new Integer(600)); hm.put("Backpack", new Integer(1200));Now, retrieve the keys −Set keys = hm.keySet(); Iterator i = keys.iterator(); while (i.hasNext()) ... Read More

Java Program to count letters in a String

karthikeya Boyini

karthikeya Boyini

Updated on 31-May-2024 16:23:29

20K+ Views

Let’s say we have the following string, that has some letters and numbers.String str = "9as78";Now loop through the length of this string and use the Character.isLetter() method. Within that, use the charAt() method to check for each character/ number in the string.for (int i = 0; i < str.length(); ... Read More

Previous 1 ... 4 5 6 7 8 ... 220 Next
Advertisements