Linear / Sequential Search Example in Java
Quick Java code snippet to show Linear / Sequential Search. import java.util.Scanner; public class LinearSearchExample { public static void main(String args[]) { int i, totalCount, search,...
View ArticleString Concatenation Test in Java
Sample Java program to concatenate two strings using plus (+) concatenation operator. public class StringConcatination { public static void main(String args[]) { String str1 = "Hello"; String str2 =...
View ArticleHow to Test String Equality in Java ?
Sample program to test String Equality in Java using equals to (==) operator and String.equals() method. public class StringEqualsTest { public static void main(String[] args) { String str1 = "hello";...
View ArticleString length and trim string in java
Code snippet explains the usage of String class length and trim() method. The length() method returns the length of this string. The trim() method returns a copy of the string, with leading and...
View ArticleInsertion sort example in Java
Code snippet to sort array using insertion sort algorithm in java. public class InsertionSortExample { static int step = 1; public static void main(String[] args) { int[] array = { 17, 21, 191, 3, 23,...
View ArticleSort Array ascending or descending using comparator in Java
Quick Java code snippet to sort Array ascending or descending using comparator in Java. import java.util.Arrays; import java.util.Comparator; public class SortFruitObject { public static void...
View ArticleHow to Trust All Certificates for HttpURLConnection in Android
The following code snippet will help you to disables the SSL certificate checking for new instances of HttpsURLConnection in Android. Note: You can use this code for testing purpose only and remove...
View ArticleHow to Calculate Image Dimensions in Java
The following code snippet shows how to calculate image dimension in java by reading the file from specified path. public static Dimension getImageDimension(final File path) { if (path == null) return...
View ArticleHow to Generate Unique File Name When Saving a File in Java
The following code snippet shows how to get unique file name when saving file in java. It first checks if already a file exist with the specified name, then it appends a number to end. public static...
View ArticleHow to Generate Gravtar Image Url from Email in Java
The following code snippet shows how to generate Gravatar URLs from email address. This utility method alows you to pass the size of your email. public String getGravatarUrl(String email, int size) {...
View ArticleHow to Add Click Listener to Android Switch
A Switch is a two-state toggle switch widget that can select between two options. Add Switch control to your Activity or Fragment layout as follows. <Switch android:id="@+id/wifi_switch"...
View ArticleHow to Programmatically Turn on and off Wifi on Android Device
Use the following code snippets to turn on and off wifi on Android devices. Switch toggle = (Switch) findViewById(R.id.wifi_switch); toggle.setOnCheckedChangeListener(new...
View ArticleInsertion sort example in Java
Code snippet to sort array using insertion sort algorithm in java. public class InsertionSortExample { static int step = 1; public static void main(String[] args) { int[] array = { 17, 21, 191, 3, 23,...
View ArticleSort Array ascending or descending using comparator in Java
Quick Java code snippet to sort Array ascending or descending using comparator in Java. import java.util.Arrays; import java.util.Comparator; public class SortFruitObject { public static void...
View ArticleString Concatenation Test in Java
Sample Java program to concatenate two strings using plus (+) concatenation operator. public class StringConcatination { public static void main(String args[]) { String str1 = "Hello"; String str2 =...
View ArticleHow to Test String Equality in Java ?
Sample program to test String Equality in Java using equals to (==) operator and String.equals() method. public class StringEqualsTest { public static void main(String[] args) { String str1 = "hello";...
View ArticleInsertion sort example in Java
Code snippet to sort array using insertion sort algorithm in java. public class InsertionSortExample { static int step = 1; public static void main(String[] args) { int[] array = { 17, 21, 191, 3, 23,...
View ArticleSort Array ascending or descending using comparator in Java
Quick Java code snippet to sort Array ascending or descending using comparator in Java. import java.util.Arrays; import java.util.Comparator; public class SortFruitObject { public static void...
View ArticleString Concatenation Test in Java
Sample Java program to concatenate two strings using plus (+) concatenation operator. public class StringConcatination { public static void main(String args[]) { String str1 = "Hello"; String str2 =...
View ArticleHow to Test String Equality in Java ?
Sample program to test String Equality in Java using equals to (==) operator and String.equals() method. public class StringEqualsTest { public static void main(String[] args) { String str1 = "hello";...
View Article