Quantcast
Channel: Java – StackTips
Browsing all 50 articles
Browse latest View live

Image may be NSFW.
Clik here to view.

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 Article


Image may be NSFW.
Clik here to view.

String 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 Article


Image may be NSFW.
Clik here to view.

How 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

Image may be NSFW.
Clik here to view.

String 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 Article

Image may be NSFW.
Clik here to view.

Insertion 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 Article


Image may be NSFW.
Clik here to view.

Sort 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 Article

How 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 Article

How 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 Article


How 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 Article


How 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 Article

How 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 Article

How 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 Article

Image may be NSFW.
Clik here to view.

Insertion 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 Article


Image may be NSFW.
Clik here to view.

Sort 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 Article

Image may be NSFW.
Clik here to view.

String 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 Article


Image may be NSFW.
Clik here to view.

How 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

Image may be NSFW.
Clik here to view.

Insertion 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 Article


Image may be NSFW.
Clik here to view.

Sort 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 Article

String 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 Article

How 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
Browsing all 50 articles
Browse latest View live