Core java
- 07 May
Java String indexOf example
String’s indexOf method is used to find out index of any character or sub string. indexOf method can take char or string as argument and also you can provide fromIndex(Index after which you want to use indexOf method) also. Methods: public int indexOf(int ch) returns index of first occurrence of character within String public int […]
- 06 May
Java String substring example
String’s substring method is used to fetch part of a String.It returns a new String which is substring of given String. substring is nothing but subset of given String. There are two overloaded methods for substring. Method Signature: [crayon-6743fe5e7af2b348411108/] It returns a new String which is substring of given String from specified startIndex(Inclusive) [crayon-6743fe5e7af30051066380/] It […]
- 06 May
Java String contains example
String’s contains method checks if sequence of characters can be found in String. It returns true if character sequence is present in String else return false. Method Signature: [crayon-6743fe5e7b004200955700/] String contains Example: [crayon-6743fe5e7b007917568440/] When you run above program, you will get below output: [crayon-6743fe5e7b008952521520/] Please note that contains method is case sensitive as you can […]
- 06 May
Java String concatenate example
String concatenate is a way to join multiple Strings to create large String. There are many places where we use to do String concatenate. For example: When you override toString() method of object, you concatenate multiple attributes to create a big String that represent that object. 3 ways to concatenate String Using + operator Using String’s […]
- 06 May
How to split a String in java
In this post, we will see how to split a String by delimiter in java. Sometimes, we need to split a String by delimiter for example: while reading a csv file, we need to split string by comma(,). We will use String class’s split method to split a String. This split(regex)Â takes a regex as […]
- 04 May
How to convert Char Array to String in java
There are multiple ways to convert Char Array to String in java. Some of them are: Using String class’s constructor (By passing Char array to contructor) Using String class’s valueOf method Using iterating char array Example: [crayon-6743fe5e7b299195585861/] When you run above program, you will get below output [crayon-6743fe5e7b29d750498660/] Other String Programs are : How to […]
- 04 May
How to convert String to Char Array in java
Java String’s toCharArray() method can be used to convert String to char Array in java. It is simplest method to convert String to char Array. Example: [crayon-6743fe5e7b337389401046/] When you run above program, you will get below output: [crayon-6743fe5e7b33a629457445/] Other String Programs are : String : How to reverse String in java How to check if […]
- 01 May
How to sort HashMap in java by keys and values
HashMap does not preserve order of element but what if you want to sort it by keys or values. In this post, we will see how to sort HashMap by keys or values. Java HashMap tutorial: HashMap in java HashMap internal working hash and indexfor method in HashMap hashcode and equals in java sort HashMap […]
- 01 May
LinkedHashSet in java
In this post, we will see about LinkedHashSet in java. LinkedHashSet is same as HashSet except that it maintains insertion order. Some points about LinkedHashSet LinkedHashSet implements Set interface and extends HashSet class. LinkedHashSet maintains insertion order, so when you will be able to access elements in the order they were inserted like ArrayList. Example: LinkedHashSetMain.java [crayon-6743fe5e7b587332159883/] When you run […]