Posts

Showing posts from March, 2020

Jackson – Convert JSON Array of Objects to List

Hello everyone, Here we will show how to convert JSON array String to List The Jackson library is composed of three components: Jackson Databind, Core, and Annotation. Jackson Databind has internal dependencies on Jackson Core and Annotation. Therefore, adding Jackson Databind to your Maven POM dependency /Gradle list will include the other dependencies as well. Maven (pom.xml)   <dependency> <groupId> com.fasterxml.jackson.core </groupId> <artifactId> jackson-databind </artifactId> <version> 2.9.8 </version> </dependency> Gradle (build.gradle)   implementation group: 'com.fasterxml.jackson.core' , name: 'jackson-core' , version: '2.13.2' JSON Array of Objects [ { "name" : "knowledgefactory1" , "salaray" : 1000 }, { "name" : "knowledgefactory2" , "salaray" : 1200 } ] Create an object to m

Java Program to find Largest & Smallest Number in an Array

Hello everyone, Today we will learn how to find the largest number in an array in java by sorting the array and returning the largest number.  Let's see the full example to find the largest number in the java array. Example 1: Find the largest number public class LargestInArrayExample1 { public static void main( String args[]) { int a[] = { 2 , 1 , 2 , 5 , 6 , 3 , 2 , 9 }; int b[] = { 144 , 666 , 99 , 677 , 433 , 422 , 255 }; System.out.println( "Largest: " + getLargest(a)); System.out.println( "Largest: " + getLargest(b)); } public static int getLargest( int [] a) { int temp; for ( int i = 0 ; i < a.length; i++) { for ( int j = i + 1 ; j < a.length; j++) { if (a[i] > a[j]) { temp = a[i]; a[i] = a[j]; a[j] = temp; } } } return a[a.length - 1

Java - Generics

In any nontrivial software project, bugs are simply a fact of life. Careful planning, programming, and testing can help reduce their pervasiveness, but somehow, somewhere, they'll always find a way to creep into your code. This becomes especially apparent as new features are introduced and your code base grows in size and complexity. Fortunately, some bugs are easier to detect than others. Compile-time bugs, for example, can be detected early on; you can use the compiler's error messages to figure out what the problem is and fix it, right then and there. Runtime bugs, however, can be much more problematic; they don't always surface immediately, and when they do, it may be at a point in the program that is far removed from the actual cause of the problem. Generics add stability to your code by making more of your bugs detectable at compile time. Generic Methods You can write a single generic method declaration that can be called with arguments of different types. Based on