how to check if string contains only alphabets in java

How to check if string contains only alphabets in java: To check whether a string contains only alphabets or not, implement below logic.

Output:

  Recommended Posts: How to check if string contains only digits in Java How to remove last element from an ArrayList Remove element from ArrayList How to swap two… Read More »

how to check if string contains only digits in java

How to check if string contains only digits in java: To check whether a string contains only digits or not, implement below logic.

Output:

  Recommended Posts: How to check if string contains only alphabets in Java How to remove last element from an ArrayList Remove element from ArrayList How to swap two… Read More »

Operators in Java

Operators in Java: Operators are special symbols that perform specific operations in Java. Below are the different types of operators present in Java. 1 Arithmetic operators 2. Bitwise operators 3. Relational operators 4. Boolean logical operators 5. Ternary operator.   1. Arithmetic operators: These are used in mathematical expressions. Operator Description + Additions – Subtraction… Read More »

Widening and Narrowing in Java

Widening and Narrowing in Java: In this article, you are going to learn what is widening and narrowing in Java. Widening: Widening is also known as Upcasting. Widening casting is automatic. It happens when we pass a variable of smaller size data type to larger data type. Widening takes place when a reference variable of… Read More »

Type casting in Java

Type casting in Java: Automatic, non-explicit change of data type is known as Conversion. Type casting is of two types. 1. Widening / Implicit / Automatic type casting 2. Narrowing / Explicit / Manual type casting.   1 Implicit type casting: Variable of smaller capacity can be assigned to another variable of bigger capacity. byte… Read More »

Java variable declaration and assignment

Java variable declaration and assignment: In any Java program, variable is the basic unit of storing data. A variable can be declared by using an identifier i.e the variable name and a data type. We can also initialize a variable when it is declared. In Java, before using any variable, it should be declared. At… Read More »

Java Data Types

Java Data Types: Java is a strongly typed language. It means all the variables must be declared before using them. Java data types of are of two types. 1. Primitive data type 2. Non-primitive data type   1. Primitive Data Types: These are predefined by the language and is named by a reserved keyword. Example:… Read More »

Generate random number between 1 to 5 in Java

How to generate random number between 1 to 5 in Java: We can use nextInt() method of Random class to generate random number between 1 to 5 in java.

Output:

Note: If we just use nextInt(5), then it will give a random number between 0 to 4. So if you don’t want 0… Read More »

Generate random number between 1 to 10 in Java

How to generate random number between 1 to 10 in Java: We can use nextInt() method of Random class to generate random number between 1 to 10 in java.

Output:

Note: If we just use nextInt(10), then it will give a random number between 0 to 9. So if you don’t want 0… Read More »

Swap two numbers without using third variable in Java

Swap two numbers without using third variable in Java: You have given two numbers and you have to swap two numbers without using third variable in Java. When you use a third variable its easy to to swap numbers as below.

But when you can’t use third/temporary variable then you can follow below method.… Read More »

Capitalize first letter of each word in java

Capitalize first letter of each word in Java: 1. Split the string using space and assign it to an string array. 2. Loop through each string 3. Get the first letter of each string using substring method and capitalize it. 4. Get the remaining letters using another substring method which starts at index position 1.… Read More »

How to capitalize first letter of String Java

In this article, you will learn how to capitalize first letter of string java.  Here we have 2 approaches. 1. Use capitalize method of StringUtils 2. Using substring method   1. StringUtils.capitalize() method: This method is coming from apache. It capitalizes the first letter of a string. It will not capitalize any other letter. Examples:… Read More »

StringUtils capitalize

StringUtils capitalize(): This method capitalizes the first character of the string. No other characters are changed. Returns: the capitalized String, null if null String input Examples:

  Recommended Posts: Covert String to int in Java Star pattern programs in Java Get last 4 chars from String Timeout test in TestNG How to clear an… Read More »

Difference between flush and close in java filewriter

What is the difference between flush and close in java filewriter: flush() writes the contents of the buffer to the destination and makes the buffer empty for further data to store but it does not close the stream permanently. This means we can still write some more data to the stream. Whereas close() closes the… Read More »

Convert String to boolean in java

Convert String to boolean in java: In this tutorial, you are going to learn how to convert string to boolean in java. We can achieve it in two ways. 1 Boolean.parseBoolean() method 2 Boolean.valueOf() method Both the methods are null safe. It means if you pass a value other than true or false, it won’t throw null… Read More »

How to remove last element from an ArrayList in Java

How to remove last element from an ArrayList in Java: The ArrayList class is a resizable array and it can be found in the java.util package. We can remove the last element from an ArrayList using remove() method. 1 remove(int i) 2 remove(Object obj)   1. remove(int i) method: First get the size of the… Read More »

How to clear an ArrayList in Java

How to clear an ArrayList in Java: We can use java.util.List.clear() and removeAll() methods to clear elements from an ArrayList. 1. Empty an ArrayList using clear() method: Syntax:

It removes all of the elements from the list. The list will be empty after this call returns. Example:

Output:

  2. Empty an… Read More »

How to remove an element from ArrayList in Java

How to remove an element from ArrayList in Java: The ArrayList class is a resizable array and it can be found in the java.util package. We can remove an element from ArrayList in java using below methods. 1 Using remove() methods. 2. Using iterator.remove() method   1. remove() methods: ArraysList has provided two overloaded methods… Read More »

Python

Python is a popular programming language. It is used for software development. Python is used to handle big data and to perform complex operations. Python works on different platforms  like windows, mac, linux, raspberry pi. Python code is readable and it is similar to combination of english and mathematics. While loop in python:

Output:… Read More »

Arrays toString method in java

Arrays toString method in java: Returns a string representation of the contents of the specified array. If the array contains other arrays as elements, they are converted to strings by the Object.toString() method inherited from Object, which describes their identities rather than their contents.The value returned by this method is equal to the value that… Read More »

Arrays sort in java

Arrays.sort() method in java is used to sort the elements in ascending or descending order. Sorts the specified array of objects into ascending order, according to the natural ordering of its elements. All elements in the array must implement the Comparable interface. Furthermore, all elements in the array must be mutually comparable (that is, e1.compareTo(e2)… Read More »

Arrays.equals() in java

Arrays.equals() method returns true if the two specified arrays of longs are equal to one another. Two arrays are considered equal if both arrays contain the same number of elements, and all corresponding pairs of elements in the two arrays are equal. In other words, two arrays are equal if they contain the same elements… Read More »

Arrays deepEquals in java

Arrays deepEquals in java: It returns true if the two specified arrays are deeply equal to one another. Unlike the equals(Object[],Object[]) method, this method is appropriate for use with nested arrays of arbitrary depth.Two array references are considered deeply equal if both are null, or if they refer to arrays that contain the same number… Read More »

binary search in java

Searches the specified array for the specified object using the binary search algorithm. The array must be sorted into ascending order according to the natural ordering of its elements (as by the sort(Object[]) method) prior to making this call. If it is not sorted, the results are undefined. (If the array contains elements that are… Read More »

Arrays in Java

Arrays class contains various methods for manipulating arrays (such as sorting and searching). This class also contains a static factory that allows arrays to be viewed as lists.The methods in this class all throw a NullPointerException, if the specified array reference is null, except where noted. The documentation for the methods contained in this class… Read More »