Core java
06 October2d Arraylist java example
In this post, we will see how to create 2d Arraylist in java. Best way to create 2d Arraylist is to create list of list in java. List<List> arraylist2D = new ArrayList<List>(); Let’s create a program to implement 2d Arraylist java. package org.arpit.java2blog; import java.util.ArrayList; import java.util.List; public class Java2DArrayListMain { public static void main(String[] […]
06 OctoberJava isNumeric method
In this post, we will see how to implement isNumeric method in java. There are many way to check if String is numeric or not. [toc] Let’s see one by one. Using regular expressions You can use below regular expression to check if string is numeric or not. [-+]?\\d*\\.?\\d+ package org.arpit.java2blog; public class JavaisNumericMain { […]
06 OctoberConvert char to lowercase java
You can use Character class’s toLowerCase method to convert char to lowercase in java. Method signature public static char toLowerCase(char ch) Parameters ch is primitive character type. Return type return type is char. If char is already lowercase then it will return same. package org.arpit.java2blog; public class JavaToLowercaseMain { public static void main(String[] args) { […]
06 OctoberConvert char to uppercase java
You can use Charater class’s touppercase method to convert char to uppercase in java. Method signature public static char touppercase(char ch) Parameters ch is primitive character type. Return type return type is char. If char is already uppercase then it will return same. package org.arpit.java2blog; public class JavaToUpperCaseMain { public static void main(String[] args) { […]
06 OctoberJava isLetter method
Character class’s isletter method can be used to check if character is letter or not. Method signature public static boolean isLetter(char ch): Parameters ch is primitive character type. Return type boolean is primitive character type. package org.arpit.java2blog; public class JavaIsLetterMain { public static void main(String[] args) { System.out.println(Character.isLetter('a')); System.out.println(Character.isLetter('Y')); System.out.println(Character.isLetter('5')); System.out.println(Character.isLetter('&')); } } When you […]
06 OctoberFix cannot make static reference to non-static method
In this post, we will see how to solve cannot make static reference to non-static method. [toc] Let’s understand this error with the help of example. package org.arpit.java2blog; public class JavaHelloWorld { public static void main(String args[]) { sayHello(); } public void sayHello() { System.out.println("Hello world from java2blog"); } } Above program won’t compile and […]
06 OctoberImplement distance formula in java
In this post, we will see how to implement distance formula between two points in java. Formula to find distance between two points ( x1, y1) and (x2 , y2) is d= sqrt( (x2-x1)^2+ (y2 – y1)^2) Here is simple program to calculate distance between two points in java. package org.arpit.java2blog; public class calculateDistanceMain { […]
06 OctoberConvert decimal to binary in java
In this post, we will see how to convert decimal to binary in java. There are lot of ways to convert decimal to binary in java.Let’s explore them one by one. [toc] Using Integer.toBinaryString() method You can simply use inbuilt Integer.toBinaryString() method to convert a decimal package org.arpit.java2blog; public class DecimalToBinaryInBuiltMain { public static void […]
05 OctoberCalculate total surface area of Cylinder in java
In this post, we will see how to calculate total surface area of Cylinder in java. Formula of calculating total surface area of Cylinder is: Surface area of Cylinder = 2 *Π * r * r + 2 *Π * r * h Where r is radius of cylinder and h is height of cylinder […]