• 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: public String substring(int startIndex) It returns a new String which is substring of given String from specified […]

  • 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: public boolean contains(CharSequence s) String contains Example: package org.arpit.java2blog; public class StringContainsMethodExample { public static void main(String[] args) { String str = "Hello world from java2blog.com"; if […]

  • 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: package org.arpit.java2blog; public class CharArrToStringMain { /* * @ Author : Arpit Mandliya */ public static void main(String args[]) […]

  • 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: package org.arpit.java2blog; public class StringToCharArrayMain { /* * @Author: Aprit Mandliya */ public static void main(String[] args) { String str="java2blog"; char[] charArr=str.toCharArray(); for (int i = 0; i < […]

  • 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 package org.arpit.java2blog; import java.util.LinkedHashSet; […]

  • 29 April

    HashMap in java

    HashMap is hash table based implementation of Map interface. It stores entry in key-value pairs. It maps keys to values. It is one of the most used Collection. [toc] Java HashMap HashMap implements Map an interface that maps a key to value. It is not synchronized and is not thread-safe. Duplicate keys are not allowed […]

Subscribe to our newletter

Get quality tutorials to your inbox. Subscribe now.