Sunday, December 10, 2017

Interesting facts


It's a quirk of language.
  
In English many animal groups are named based on some virtue or vice or other idea associated with the animal.  
1)Lions were traditionally seen as regal and elevated so their group is called a pride.  
2)Owls are associated with wisdom so a group of owls is called a parliament
3) Monkeys form troops, many animal groups are called herds, birds that don't have a specific name for their groupings form flocks,   
3)The proper name for a group of crows is "murder". 






package com.tvidushi.json;
import java.io.Reader;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Stream;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.JSONValue;
public class JSONUtils{
public static JSONObject convertObjToString(Student student){
JSONObject obj = new JSONObject();
obj.put("Roll No",student.getRollno());
obj.put("name",student.getName());
obj.put("Marks",student.getMarks());
return obj;
}
public static JSONArray convertObjectListToJSONArray(){
JSONArray arr = new JSONArray();
Student.getStudentList().forEach(x->{
arr.add(convertObjToString(x));
});
System.out.println(arr);
return arr;
}
public static void convertJSONArrayToStudenList(JSONArray array){
Stream.of(array).forEach(x->{
Object obj=JSONValue.parse(JSONValue.toJSONString(x));
JSONObject jsonObject = (JSONObject) obj;
Integer rollno = (Integer) jsonObject.get("rollno");
String name = (String) jsonObject.get("name");
Integer marks=(Integer) jsonObject.get("marks");
System.out.println(rollno+" "+name+" "+marks);
});
}
public static void test(JSONArray x){
}
public static void main(String args[]){
JSONArray array = convertObjectListToJSONArray();
convertJSONArrayToStudenList(array);
}
static class Student {
public int rollno;
public String name;
public int marks;
public Student(int rollno,String name,int marks ){
this.rollno = rollno;
this.name = name;
this.marks = marks;
}
public static Student getStudent(){
return new Student(1, "Ayush", 20);
}
public static List<Student> getStudentList(){
return Arrays.asList(new Student(1, "Ayush", 20),
new Student(2, "Bob", 30),
new Student(3, "Catherine", 24),
new Student(4, "Dinesh", 21),
new Student(5, "Avinash", 20),
new Student(6, "Nash", 30),
new Student(7, "Sara", 34),
new Student(8, "Rob", 21));
}
public int getRollno() {
return rollno;
}
public void setRollno(int rollno) {
this.rollno = rollno;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getMarks() {
return marks;
}
public void setMarks(int marks) {
this.marks = marks;
}
}
}
view raw JSONUtils.java hosted with ❤ by GitHub

No comments:

Post a Comment