1

I use a method which returns a list of Lists. This List contains 6 Lists, each List contains 3 String : [[5, 0.01, 2], [7, 0.01, 3], [3, 0.02, 2], [8, 0.05, 3],[9, 0.1, 2], [6, 0.1, 3]]

Continuing from a previous answer...

But I have to split again this list in 3 differents values : [3, 0.01, 2]

The main goal is to transform this list of object in list of Change. A Change :

public class Change {
  private static final String value;
  private static final String amount;
  private static final String column;
...
}

I attempted but I think it's not the greatest way to accomplish :

List saisie = ServiceTableau.getInstance().deserialiser(quantites);
List<String> saisieToStrings = new ArrayList<String>();

for (Object object : saisieIHM) {
    saisieIHMToStrings.add(object != null ? object.toString() : null);
}

Is there a system method to do this? I can't use external libraries

2
  • 1
    Are you sure the fields in Change should be static? Commented May 23, 2014 at 13:18
  • Indeed while testing the solution I change it ;) Commented May 24, 2014 at 8:59

1 Answer 1

1

Create a constructor in your Change class:

public Change( String input) {
    String[] values = input.split(",");
    this.value = values[0];
    this.amount = values[1];
    this.column = values[2];
}

And then pass that string when you create the list:

List<Change> saisieToStrings = new ArrayList<Change>();
for (Object object : saisieIHM) {
    saisieIHMToStrings.add( new Change( object.toString()));
}
Sign up to request clarification or add additional context in comments.

1 Comment

Constructor should throw illegal argument EX if the input is not made correctly, proposed change.

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.