Core java
- 06 October
2d 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. [crayon-67424aa0472d8628109516/] Let’s create a program to implement 2d Arraylist java. [crayon-67424aa0472df250578360/] Output: 2nd element in list3 : List3_Str2 3nd element in list1 : List1_Str3 1st element in list2 […]
- 06 October
Java 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. 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+ [crayon-67424aa04756b729262709/] Output: 223 is numeric : true […]
- 06 October
Convert char to lowercase java
You can use Character class’s toLowerCase method to convert char to lowercase in java. Method signature [crayon-67424aa047753041619251/] Parameters ch is primitive character type. Return type return type is char. If char is already lowercase then it will return same. [crayon-67424aa047757804610013/] When you run above program, you will get below output: a y b z That’s […]
- 06 October
Convert char to uppercase java
You can use Charater class’s touppercase method to convert char to uppercase in java. Method signature [crayon-67424aa0477f5409857530/] Parameters ch is primitive character type. Return type return type is char. If char is already uppercase then it will return same. [crayon-67424aa0477f8789108629/] When you run above program, you will get below output: A Y F U That’s […]
- 06 October
Java isLetter method
Character class’s isletter method can be used to check if character is letter or not. Method signature [crayon-67424aa047882332918922/] Parameters ch is primitive character type. Return type boolean is primitive character type. [crayon-67424aa047885210955470/] When you run above program, you will get below output: true true false false That’s all about java Character’s isletter method.
- 06 October
Fix 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. Let’s understand this error with the help of example. [crayon-67424aa04791a976949242/] Above program won’t compile and you will get below compilation error. It says cannot make static reference to non-static method sayHello from the type JavaHelloWorld Why are you getting […]
- 06 October
Implement 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. [crayon-67424aa0479cd509271515/] Here we have used math.sqrt […]
- 06 October
Convert 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. Using Integer.toBinaryString() method You can simply use inbuilt Integer.toBinaryString() method to convert a decimal [crayon-67424aa047a6b540484431/] Output: Binary representation of 12 : 1100 Binary representation […]
- 05 October
Calculate 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 […]