Java Issue and Solution
Tuesday, September 10, 2013
Thursday, October 11, 2012
How to call default Constructor from a Parametarized Constructor in Java
Code Snap for above Issue is...............
public class Test {
int i;
Test(){
System.out.println("hariom");
}
public Test(int i){
this();
this.i = i;
System.out.println("Hariom23"+i);
}
public static void main(String a[]){
Test test = new Test(8);
}
}
And the Output will be ....
hariom Hariom238
How to compate objects value of two diffrent list in Java
Java Code for above issue...
public static class A {
String headerName;
public String getHeaderName() {
return headerName;
}
public void setListBoxHeaderName(String headerName) {
this.headerName= headerName;
}
public A(String headerName) {
super();
this.headerName = headerName;
}
public boolean equals(A rData) {
boolean bEqual = false;
if (this.getHeaderName() != null && rData.getHeaderName() != null
&& this.getHeaderName().equals(rData.getHeaderName())) {
bEqual = true;
}
return bEqual;
}
}
And for comparing two list the code is as follows...
for (A value1 : listA1) {
for (A value2: listA) {
if (value2.equals(value1 )) {
listA.remove(value2);
break;
}
}
}
This is what the exact solution i used Thanks
Tuesday, October 9, 2012
Create JSON Object and Retrive Data
I Have created a JSON Object and saved it into database then i am getting the it from database as a String and again converting it into as a Java Object.
1- How we will create a JSON object from String
List mylist; //Data is something like this [Sub Type, F.P., P.P., Process,Status]
JSONObject json = new JSONObject();
json.accumulate("COLUMN", mylist);
String jsonObjString = json.toString();
2-If you saved above JSON Object into database and retrieving it again You will get data something like i have commented below...And you can retirve it by Below code
String jsonString;//Data will something like this {"COLUMN":["Sub Type","F.P.","P.P.","Process","Status"]}
JSONObject jsonObj= new JSONObject();
jsonObj = jsonObj.fromObject(jsonString);
JSONArray columnName = (JSONArray) obj.get("COLUMN");
for (int i = 0; i < columnName.size(); i++) {
System.out.println(columnName.getString(i));
}
NOTE:- I used net.sf.json Jar
Subscribe to:
Comments (Atom)
