I've created a DataGrid so:
DataGrid<String> grid = new DataGrid<String>();
grid.setPageSize(4);
TextColumn<String> date = new TextColumn<String>() {
public String getValue(String object) {
return object;
}
};
grid.addColumn(date, "Date");
TextColumn<String> time = new TextColumn<String>() {
public String getValue(String object) {
return object;
}
};
grid.addColumn(time, "Time");
TextColumn<String> number = new TextColumn<String>() {
public String getValue(String object) {
return object;
}
};
grid.addColumn(number, "Number");
Now I'd like to populate it but I don't understood how to do it because I have these String[] and they must be splitted also:
textString[1]="01/01/2014;10:00;300";
textString[2]="02/02/2014;11:00;400"; ...
Thanks in advance.
UPDATE
#Sturmination I followed your hint but there is another problem for this code(assuming that splitting is done):
..
protected static List<Example> EXAMPLES = null;
..
public void method() {
...
EXAMPLES = Arrays.asList(new Example("01/01/2014", "10:00", "300"));
grid.setRowCount(EXAMPLES.size(), true);
grid.setRowData(0, EXAMPLES);
..
}
It returns this error:
The method setRowData(int, List<? extends String>) in the type AbstractHasData<String> is not applicable for the arguments (int, List<Example>)
And it suggests : Change type of EXAMPLES to List<? extends String> but it doesn't work anyway.
Have you tried this:
DataGrid<String> grid = new DataGrid<String>();
grid.setPageSize(4);
TextColumn<String> date = new TextColumn<String>() {
public String getValue(String object) {
return object.split(';')[0];
}
};
grid.addColumn(date, "Date");
TextColumn<String> time = new TextColumn<String>() {
public String getValue(String object) {
return object.split(';')[1];
}
};
grid.addColumn(time, "Time");
TextColumn<String> number = new TextColumn<String>() {
public String getValue(String object) {
return object.split(';')[2];
}
};
grid.addColumn(number, "Number");
A nicer approach would be to create a new Java Bean for your rows and convert your String[] items to a List<Row> of the new row objects
You can use String[] in your code:
DataGrid<String> grid = new DataGrid<String>();
TextColumn<String[]> date = new TextColumn<String[]>() {
public String getValue(String[] object) {
return object[0];
}
};
Split your strings when you add them:
private ListDataProvider<String[]> dataProvider = new ListDataProvider<String[]>();
private List<String[]> displayItems = dataProvider.getList();
...
for (String textString : textStrings) {
displayItems.add(textString.split(";");
}
I would do it like this, if size of you data is not huge.
Create a class
Class YourClass{
private String date, time, number;
public YourClass(String date, String time, String nuber){
this.date=date;
this.time=time;
this.number=number;
}
//getters and setters here
}
Create a method to conver you values
private List<YourObject> convert(String[] values){
List<YourClass> data= new ArrayList<YourClass>();
String date, time, number;
for(i=0; values.size(); i++){
values[i] //split the string and asign values to date, time and number
dataList.add(new YourClass(date, time, number));
}
return dataList;
}
Add you values to DataGrid
ListDataProvider<YourClass> provider= new ListDataProvider<YourClass>();
List<YourClass> dataList = new ArrayList<YourClass>();
dataList.addAll(convert(textString[]));
provider.addDataDisplay(grid);
provider.setList(dataList);
Then in your Columns just:
return object.getDate();
return object.getTime();
return object.getNumber();
Related
I need help with my RecyclerView. I have a atring array from my SQL Database which looks like this:
{"success":true,"0":{"order_number":"078","typ_first":"E3rft","typ_last":"Split","order_date_time":"2016-10-11 19:20:03"},"1":{"order_number":"166","typ_first":"E483f","typ_last":"Split_test","order_date_time":"2016-10-12 18:39:30"}}
In my RecyclerView I have the following fields:
order_number
typ_all (type first and last)
date(only a date without time)
This is how I get my string array:
String plansData = plansPreferenceData.getString("plansPreferenceData", "");
This is how I set the data to my RecyclerView:
// Set plan data
Plans plan = new Plans("123", "E3rft Split", "11.10.2016");
// Add Object to list
planList.add(plan);
// Notify data changes
pAdapter.notifyDataSetChanged();
My Plans class:
public class Plans {
private String planTitle, planType, planDate;
public Plans(String planTitle, String planType, String planDate) {
this.planTitle = planTitle;
this.planType = planType;
this.planDate = planDate;
}
public void setPlanTitle(String planTitle) {
this.planTitle = planTitle;
}
public String getPlanTitle() {
return planTitle;
}
public void setPlanType(String planType) {
this.planType = planType;
}
public String getPlanType() {
return planType;
}
public void setPlanDate(String planDate) {
this.planDate = planDate;
}
public String getPlanDate() {
return planDate;
}
}
My onCreateView:
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_training, container, false);
preparePlansData();
return view;
}
My preparePlansData():
private void preparePlansData() {
// Set plan data
Plans plan = new Plans("123", "fkfjfjeje", "21.04.1977");
// Add Object to list
planList.add(plan);
plan = new Plans("test", "tttt", "22.01.2017");
planList.add(plan);
// Notify data changes
pAdapter.notifyDataSetChanged();
}
My question is how can I get the information out of the string array into my adapter? I also need to format the date before adding. Thanks for your help!
read about Gson here:
http://guides.codepath.com/android/leveraging-the-gson-library
After that you will be able to write code like that:
Type type = new TypeToken<Map<Integer, Plans>>(){}.getType();
Map<Integer, Plans> myMap = gson.fromJson("your json from db", type);
and use this map.values() in your adapter
your Plans class should look like this:
class Plans {
String order_number;
String typ_first;
String typ_last;
String order_date_time;
}
If you want another field names you have to use #SerializedName annotation
Finally, you should write something like that, (I do not know if syntax is 100% do not have IDE open now) :
private void preparePlansData() {
String plansData = plansPreferenceData.getString("plansPreferenceData", "");
Type type = new TypeToken<Map<Integer, Plans>>(){}.getType();
Map<Integer, Plans> myMap = gson.fromJson(plansData, type);
planList.addAll(myMap.values());
// Notify data changes
pAdapter.notifyDataSetChanged();
}
and modify your model class:
public class Plans {
#SerializedName("order_number")
String planTitle;
#SerializedName("typ_last")
String planType;
#SerializedName("order_date_time")
String planDate;
....
I hope it will help you.
Check this code (you can remove #Test annotation):
class Plans {
String typ_firstString;
String typ_last;
String order_date_time;
public Plans(String typ_firstString, String typ_last, String order_date_time) {
this.typ_firstString = typ_firstString;
this.typ_last = typ_last;
this.order_date_time = order_date_time;
}
}
class PlansResponse {
boolean status;
List<Plans> plans;
}
#Test
public void testPlacesResponseDeserializer() {
Gson gson = new GsonBuilder()
.registerTypeAdapter(PlansResponse.class, new PlansResponseDeserializer())
.create();
String jsonString = "{\"success\":true,\"0\":{\"order_number\":\"078\",\"typ_first\":\"E3rft\",\"typ_last\":\"Split\",\"order_date_time\":\"2016-10-11 19:20:03\"},\"1\":{\"order_number\":\"166\",\"typ_first\":\"E483f\",\"typ_last\":\"Split_test\",\"order_date_time\":\"2016-10-12 18:39:30\"}}";
PlansResponse plansResponse = gson.fromJson(jsonString, PlansResponse.class);
assert plansResponse.status == true;
assert plansResponse.plans.size() == 2;
}
class PlansResponseDeserializer implements JsonDeserializer<PlansResponse> {
private String getElementAsString(JsonObject jsonObject, String key) {
JsonElement element = jsonObject.get(key);
return element.getAsString();
}
#Override
public PlansResponse deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
PlansResponse plansResponse = new PlansResponse();
List<Plans> plansList = new ArrayList<>();
Gson gson = new Gson();
Type type = new TypeToken<Map<String, JsonObject>>(){}.getType();
Map<String, JsonElement> map = gson.fromJson(json, type);
for(Map.Entry<String, JsonElement> entry : map.entrySet()) {
String key = entry.getKey();
if("success".equals(key)) {
JsonPrimitive jsonPrimitive = (JsonPrimitive) entry.getValue();
plansResponse.status = jsonPrimitive.getAsBoolean();
continue;
}
JsonObject jsonObject = (JsonObject)entry.getValue();
String typ_firstString = getElementAsString(jsonObject, "typ_first");
String typ_last = getElementAsString(jsonObject, "typ_last");
String order_date_time = getElementAsString(jsonObject, "order_date_time");
plansList.add(new Plans(typ_firstString, typ_last, order_date_time));
}
plansResponse.plans = plansList;
return plansResponse;
}
}
I have a tree map with a following key value pair combination
Map is declared as follows
Map<String, List<Bean>> outputMap = new TreeMap<String,List<Bean>>();
Corresponding code will be
for (String course_date : shiftSet) {
Bean courseBean = null;
boolean valueExists = false;
for (Entry<String, List<Bean>> entry: courseMap.entrySet()){
valueExists = false;
String studentDetail = entry.getKey();
String [] studentSet = StringUtils.getArray(studentDetail , ",");
String studentId = studentSet[0];
String courseId = studentSet[1];
for(Bean resultBean : entry.getValue()){
if(course_date.equalsIgnoreCase(resultBean.getCourseDate()){
valueExists = true;
}
}
if(!valueExists ) {
courseBean = new Bean();
courseBean.setStudent(studentId);
courseBean.setCourse(courseId);
List<Bean> courseList = entry.getValue();
courseList.add(courseBean);
outputMap.put(studentId+courseId, courseList);
}
}
}
And finally the OutputMap needs to be inserted to courseMap
OutputMap result will be
{ADV001,STU02=
[Bean[course_id=ADV1, student_id=STU1_2,Day=Wed-Night,courseDate=12-Feb-2014],
Bean[course_id=ADV1, student_id=STU1_2,Day=Tue-Day,courseDate=11-Feb-2014],
Bean[course_id=ADV1, student_id=STU1_2,Day=Tue-Night,courseDate=11-Feb-2014],
Bean[course_id=ADV1, student_id=STU1_2,Day=Wed-Day,courseDate=12-Feb-2014]]
So Here i need to sort the outputMap based on courseDate?Kindly help on how the desired output can be achieved ?
Thanks in advance..
A TreeMap sorts the elements by their key, if courseDate is part of the values, you'd have to use a TreeSet, e.g.
import java.util.Set;
import java.util.TreeSet;
public class Example {
public static void main(String[] args) {
Set<Dummy> example = new TreeSet<>();
example.add( new Dummy(7, "first dummy"));
example.add( new Dummy(2, "second dummy"));
example.add( new Dummy(3, "third dummy"));
System.out.println(example);
}
static class Dummy implements Comparable<Dummy>{
int courseDate;
String name;
Dummy(int courseDate, String name) {
this.courseDate = courseDate;
this.name = name;
}
#Override
public String toString() {
return String.format("[Dummy courseDate=%s, name=%s]", courseDate, name);
}
#Override
public int compareTo(Dummy o) {
// here you specify how the TreeSet will order your elements
return Integer.compare(this.courseDate, o.courseDate);
}
}
}
I have a table with has the columns namely
recordID, recordName , titleFeild, titleIDMap, titleId, titleStartDate, titleEndDate, languageId
Now I have convert the data from above columns to the JSON object data which looks like below
{
"recordId" :10,
"recordName" : "RECORDS",
"records" : [ {
"titleField" : 1,
"titleIDMap" : null,
"titleId" : 500,
"titleStartDate" : "2013-12-22T00:00:00.000+0000",
"titleEndDate" : "2013-12-03T00:00:00.000+0000",
"languageId" : 20
}]
}
Please note that records is an array of columns ( titleFeild,titleIDMap,titleId,titleStartDate,titleEndDate,languageId)
The code so far I have developed is
List<Object[]> objList = dao.getStatus();
Integer result = null;
JSONObject jsonData = new JSONObject();
JSONArray jsonDataArray = new JSONArray();
if(objList!=null && objList.size()>10000)
{
for (Object[] nameObj : objList) {
jsonData.put("", nameObj.get(arg0) );
}
}
How do I construct the JSON Object from the columns data ?
You can easily achieve this with google-gson library. In simple terms you would have to create a couple of Pojos (with reference to another containin a list of references).
Consider RecordID and RecordName as Meta Data.
Create a pojo representing this information:
public class DbMetaPojo {
private int recordID;
private String recordName;
private List<Record> records;
public List<Record> getRecords() {
return records;
}
public void setRecords(List<Record> records) {
this.records = records;
}
public String getRecordName() {
return recordName;
}
public void setRecordName(String recordName) {
this.recordName = recordName;
}
public int getRecordID() {
return recordID;
}
public void setRecordID(int recordID) {
this.recordID = recordID;
}
}
Create another pojo with the actual Record fields:
public class Record {
public int getTitleFeild() {
return titleFeild;
}
public void setTitleFeild(int i) {
this.titleFeild = i;
}
public String getTitleIDMap() {
return titleIDMap;
}
public void setTitleIDMap(String titleIDMap) {
this.titleIDMap = titleIDMap;
}
public int getTitleId() {
return titleId;
}
public void setTitleId(int titleId) {
this.titleId = titleId;
}
public String getTitleStartDate() {
return titleStartDate;
}
public void setTitleStartDate(String titleStartDate) {
this.titleStartDate = titleStartDate;
}
public String getTitleEndDate() {
return titleEndDate;
}
public void setTitleEndDate(String titleEndDate) {
this.titleEndDate = titleEndDate;
}
public int getLanguageId() {
return languageId;
}
public void setLanguageId(int languageId) {
this.languageId = languageId;
}
private int titleFeild;
private String titleIDMap;
private int titleId;
private String titleStartDate;
private String titleEndDate;
private int languageId;
}
Now just a method to populate your POJOs with the relevant data (replace the hardcoding logic with your data retrieve):
public static void main(String... main) {
DbMetaPojo obj = new DbMetaPojo();
obj.setRecordID(10);
obj.setRecordName("RECORDS");
Record record = new Record();
record.setLanguageId(20);
record.setTitleEndDate("2013-12-22T00:00:00.000+0000");
record.setTitleFeild(1);
record.setTitleId(500);
record.setTitleIDMap("SOME NULL");
record.setTitleStartDate("2013-12-22T00:00:00.000+0000");
List<Record> list = new ArrayList<Record>();
list.add(record);
obj.setRecords(list);
Gson gson = new Gson();
String json = gson.toJson(obj);
System.out.println(json);
}
Output is your formed JSON:
{
"recordID": 10,
"recordName": "RECORDS",
"records": [
{
"titleFeild": 1,
"titleIDMap": "SOME NULL",
"titleId": 500,
"titleStartDate": "2013-12-22T00:00:00.000+0000",
"titleEndDate": "2013-12-22T00:00:00.000+0000",
"languageId": 20
}
]
}
EDIT:
To align to your code, you might want to do something like:
List<Object> objList = dao.getStatus();
List<DbMetaPojo> metaList = new ArrayList<DbMetaPojo> ();
if (objList != null && objList.size() > 10000) {
for (Object nameObj : objList) {
DbMetaPojo meta = new DbMetaPojo();
meta.setRecordID(nameObj[0]);
meta.setRecordName(nameObj[0]);
...
...
...
metaList.add(meta);
}
}
First of all what you have to do is retrieve the data from the columns of the table using your DAO and calling a Function from DAOIMPL which in turn will return the list of data(POJO probably).
Create a map like this which will contain your key value pair for example recordid and value,
recordname and value
Map<String,Object> objMap = new HashMap<String,Object>();
objMap.put("recordId", Record.getId());
objMap.put("recordName",Record.getName());
// Now here is the deal create another hashmap here whose key will be records "the key for your second array"
//Put the values in this second hashmap as instructed above and put it as a key value pair.
........
.......
.......
JSONObject JsonObject = JSONObject.fromObject(objMap);//This will create JSON object out of your hashmap.
objJSONList.add(JsonObject);
}
StringBuffer jsonBuffer = new StringBuffer();
jsonBuffer.append("{\"data\": {");
jsonBuffer.append(objJSONList.tostring());
jsonBuffer.append("}");
//jsonBuffer.append(",\"total\":"+ objJSONList.size());// TOTAL Optional
//jsonBuffer.append(",\"success\":true}");//SUCCESS message if using in callback Optional
Create an object which has your attribues. (recordID, recordName , titleFeild, titleIDMap, titleId, titleStartDate, titleEndDate, languageId)
Get data from dao and convert it to json. It will looks like what you want.
Gson gson = new Gson();
// convert java object to JSON format,
// and returned as JSON formatted string
String json = gson.toJson(obj);
I think your dao.getStatus() should return a List with Map keys and values. Your key would be column name and value would be content.
List<Map<String,Object>> objList = dao.getStatus();
if(objList!=null && objList.size()>10000){
for(Map<String,Object> row : objList) {
Iterator<String> keyList = row.keySet().iterator();
while(keyList.hasNext()){
String key = keyList.next();
jsonData.put(key, row.get(key));
}
}
}
For the records array you need to build it while iterating table columns.
Combining above code with building records array would be something like this..
String[] group = {"titleField","titleIDMap","titleId","titleStartDate","titleEndDate","languageId"};
List<String> recordGroup = Arrays.asList(group);
Map<Object, JSONArray> records = new HashMap<Object,JSONArray>();
List<Map<String,Object>> objList = dao.getStatus();
JSONObject jsonData = new JSONObject();
if(objList!=null && objList.size()>10000){
for(Map<String,Object> row : objList) {
int columnCount = 0;
Iterator<String> keyList = row.keySet().iterator();
while(keyList.hasNext()){
String key = keyList.next();
if(recordGroup.contains(key)){
Object recordId = row.get("recordId");
JSONArray recordArray = new JSONArray();
if(records.containsKey(recordId)){
recordArray = records.get(recordId);
JSONObject jsonObj = null;
if(columnCount >= recordGroup.size()){
jsonObj = new JSONObject();
recordarray.add(jsonObj);
columnCount = 0;
}
else {
jsonObj = (JSONObject) recordArray.get(recordArray.size()-1);
}
jsonObj.put(key, row.get(key));
columnCount++;
}
else {
JSONObject jsonObj = new JSONObject();
jsonObj.put(key, row.get(key));
recordArray.add(jsonObj);
records.put(recordId, recordArray);
}
jsonData.put("records", records.get(recordId));
}
else {
jsonData.put(key, row.get(key));
}
}
}
}
I wanted to create a table/list in Java, and I wonder what is the best way to handle it.
The table should have a structure like this:
Term propertyList entitiesList
a1 p1=1, p2=2, p3=2 T1,T2
a2 p5=0, p4=5 ,p3=3 T2,T1
a3 p1=1 ,p4=3, p3=9 T3,T1,T2
...
a10
I have a list with exactly 10 terms, and for every term there is a list of properties (deep with key and value), and the properties can be either in one or more entities.
I need some help on how to create it, e.g. should I use list, map, collection etc.
How can I add hardcoded values to them as literals in the code, and what is the best way to read data from it, taking into account performance, given that later I will need to use this for every entity and find the related properties that participate in every term.
first off Create Term class.
So you have list of Terms: List<Term>
Term class
public class Term {
private String mName = "";
private Map<String, Integer> mPropertyMap = new LinkedHashMap<String, Integer>();
private List<String> mEntitiesList = new ArrayList<String>();
public Term(String name) {
mName = name;
}
public void generate(Map<String, Integer> propertyMap, List<String> entitiesList) {
mPropertyMap = propertyMap;
mEntitiesList = entitiesList;
}
public Map<String, Integer> getPropertyMap() {
return mPropertyMap;
}
public void setPropertyMap(Map<String, Integer> propertyMap) {
this.mPropertyMap = propertyMap;
}
public List<String> getEntitiesList() {
return mEntitiesList;
}
public void setEntitiesList(List<String> entitiesList) {
this.mEntitiesList = entitiesList;
}
public String getName() {
return mName;
}
public void setmName(String name) {
this.mName = name;
}
}
Main Class
public class MyClass {
private List<Term> mTermList = null;
private void init() {
mTermList = new ArrayList<Term>();
}
private void addSomeTerm() {
Map<String, Integer> propertyMap = new LinkedHashMap<String, Integer>();
propertyMap.put("p1", 1);
propertyMap.put("p2", 2);
propertyMap.put("p3", 3);
List<String> entitiesList = new ArrayList<String>();
entitiesList.add("T1");
entitiesList.add("T2");
Term term = new Term("a1");
term.generate(propertyMap, entitiesList);
mTermList.add(term);
}
private String printTerms() {
StringBuilder buff = new StringBuilder();
for(Term currTerm : mTermList){
buff.append(currTerm.getName()).append(" ");
Map<String, Integer> propertyMap = currTerm.getPropertyMap();
Set<String> sets = propertyMap.keySet();
Iterator<String> itr = sets.iterator();
String key = null;
Integer value = null;
while(itr.hasNext()){
key = itr.next();
value = propertyMap.get(key);
buff.append(key + "=" + value).append(",");
}
buff.setLength(buff.length()-1); // remove last ','
buff.append(" ");
List<String> entitiesList = currTerm.getEntitiesList();
for(String str : entitiesList){
buff.append(str).append(",");
}
buff.setLength(buff.length()-1); // remove last ','
}
return buff.toString();
}
/**
* #param args
*/
public static void main(String[] args) {
MyClass m = new MyClass();
m.init();
m.addSomeTerm();
System.out.println(m.printTerms());
}
}
Output:
a1 p1=1,p2=2,p3=3 T1,T2
It looks like you could have the following structure:
class Term {
String id;
Map<String, String> properties;
List<Entity> entities; // (or Set<Entity> if no duplicates are allowed)
}
But it's not very clear what you mean by "deep" and by "the properties can be either in one or more entities".
I have a ArrayList with custom objects. I want to search inside this ArrayList for Strings.
The class for the objects look like this:
public class Datapoint implements Serializable {
private String stateBased;
private String name;
private String priority;
private String mainNumber;
private String groupadress;
private String dptID;
public Datapoint(){
}
public String getMainNumber() {
return mainNumber;
}
public void setMainNumber(String mainNumber) {
this.mainNumber = mainNumber;
}
public String getName() {
return name;
}
..and so on
I know how to search for a string in a ArrayList but how to do that in a ArrayList with my custom objects:
ArrayList<String> searchList = new ArrayList<String>();
String search = "a";
int searchListLength = searchList.size();
for (int i = 0; i < searchListLength; i++) {
if (searchList.get(i).contains(search)) {
//Do whatever you want here
}
}
So I want to have a function to search in my ArrayList with for example five objects for all "name" strings.
The easy way is to make a for where you verify if the atrrtibute name of the custom object have the desired string
for(Datapoint d : dataPointList){
if(d.getName() != null && d.getName().contains(search))
//something here
}
I think this helps you.
UPDATE: Using Java 8 Syntax
List<DataPoint> myList = new ArrayList<>();
//Fill up myList with your Data Points
List<DataPoint> dataPointsCalledJohn =
myList
.stream()
.filter(p-> p.getName().equals(("john")))
.collect(Collectors.toList());
If you don't mind using an external libaray - you can use Predicates from the Google Guava library as follows:
class DataPoint {
String name;
String getName() { return name; }
}
Predicate<DataPoint> nameEqualsTo(final String name) {
return new Predicate<DataPoint>() {
public boolean apply(DataPoint dataPoint) {
return dataPoint.getName().equals(name);
}
};
}
public void main(String[] args) throws Exception {
List<DataPoint> myList = new ArrayList<DataPoint>();
//Fill up myList with your Data Points
Collection<DataPoint> dataPointsCalledJohn =
Collections2.filter(myList, nameEqualsTo("john"));
}
try this
ArrayList<Datapoint > searchList = new ArrayList<Datapoint >();
String search = "a";
int searchListLength = searchList.size();
for (int i = 0; i < searchListLength; i++) {
if (searchList.get(i).getName().contains(search)) {
//Do whatever you want here
}
}
Probably something like:
ArrayList<DataPoint> myList = new ArrayList<DataPoint>();
//Fill up myList with your Data Points
//Traversal
for(DataPoint myPoint : myList) {
if(myPoint.getName() != null && myPoint.getName().equals("Michael Hoffmann")) {
//Process data do whatever you want
System.out.println("Found it!");
}
}
For a custom class to work properly in collections you'll have to implement/override the equals() methods of the class. For sorting also override compareTo().
See this article or google about how to implement those methods properly.
contains() method just calls equals() on ArrayList elements, so you can overload your class's equals() based on the name class variable. Return true from equals() if name is equal to the matching String. Hope this helps.
Use Apache CollectionUtils:
CollectionUtils.find(myList, new Predicate() {
public boolean evaluate(Object o) {
return name.equals(((MyClass) o).getName());
}
}
String string;
for (Datapoint d : dataPointList) {
Field[] fields = d.getFields();
for (Field f : fields) {
String value = (String) g.get(d);
if (value.equals(string)) {
//Do your stuff
}
}
}
boolean found;
for(CustomObject obj : ArrayOfCustObj) {
if(obj.getName.equals("Android")) {
found = true;
}
}