-1

Getting the Object value and add to Arraylist and then I have to check arraylist contains string or not.

Below is the POJO Class, finally this will get as Object

public class OrderTypeFeature{

    public OrderTypeFeature(ODataEntity entity){
        create(entity);
    }

    private String OrderType;
    private String Feature;

    public String getOrderType() {
        return OrderType;
    }

    public void setOrderType(String orderType) {
        OrderType = orderType;
    }

    public String getFeature() {
        return Feature;
    }

    public void setFeature(String feature) {
        Feature = feature;
    }

    public static ArrayList<OrderTypeFeature> getOrderTypeFeatures(String orderType){

        ArrayList<OrderTypeFeature> orderTypeFeatures = new ArrayList<>();
        ResponseObject result = new ResponseObject(ConfigManager.Status.Error);

        try {

            String resourcePath = Collections.LT_ORDERTYPEFEATURESET+"?$filter=(OrderType eq '"+ orderType +"')";

            result = DataHelper.getInstance().getEntities(resourcePath, StoreSettings.Stores.MdLV);

            if(!result.isError()){
                List<ODataEntity> entities = (List<ODataEntity>) result.Content();
                for (ODataEntity entity : entities){
                    orderTypeFeatures.add(new OrderTypeFeature(entity));
                }
            }

        }catch (Exception e){

            result.setMessage(e.getMessage());
            DliteLogger.WriteLog(OrderTypeFeature.class, AppSettings.LogLevel.Error, e.getMessage());

        }
            return orderTypeFeatures;
        }

}

Below are the links which I referred How to retrieve objects values stored in a Java ArrayList but didn't worked out

I have to get the Object Value to ArrayList and then I have to compare the Object value with the String without using For loop. Please help me guys.Thanks in Advance.

1 Answer 1

0

You can check whether an ArrayList (or in fact any class implementing the List interface) contains an element by calling

List.contains(Object)

Have a look at the Java documentation for more information.

Sign up to request clarification or add additional context in comments.

7 Comments

Hi,Thanks for your response, I have added like this.Can you please check ---- ArrayList<OrderTypeFeature> ort = new ArrayList<>(); OrderTypeFeature a = new OrderTypeFeature(); ort.add(a);
You're welcome. Your code to add the element looks good. Please mark the answer as accepted if it helped you.
Hauke, Thanks for your response, I am getting the values as null.Can you please help me on this please ?
Your code is alright, your Exception may be thrown elsewhere.
ArrayList<String> ort = new ArrayList<>(); OrderTypeFeature a = new OrderTypeFeature(); ort.add(a.getFeature()) -----this code giving me null
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.