#help with java streams

4 messages · Page 1 of 1 (latest)

little mantle
#

not sure if this is possible, but after i map the elements to atomic mass * atoms in the GRAMS case of my function, i want to return a sum of all the mapped results:

@Override
public double getConversionFactor() {

        return switch (this.getUnit()) {
            case ATOMS, MOLECULES, PARTICLES -> 6.02 * Math.pow(10, 23);
            case GRAMS -> Arrays.stream(this.getElements())
                    .map(element -> element.getAtomic_mass() * element.getAtoms())
                    . // After i map them to atomic mass * atoms, i want to add up all the results and return it
                     ;
            case MOLES -> 1;
            case LITERS -> 22.4;
        };

    }```

the other stuff in the function is irrelevant, but i thought it would be helpful to give a view of the whole function
unique scaffoldBOT
#

This post has been reserved for your question.

Hey @little mantle! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

little mantle
#
  • resolved