Java ArrayList Max maxInColumns(ArrayList lines)

Here you can find the source of maxInColumns(ArrayList lines)

Description

max In Columns

License

Open Source License

Declaration

static public ArrayList<String> maxInColumns(ArrayList<String> lines) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.ArrayList;

public class Main {
    static public ArrayList<String> maxInColumns(ArrayList<String> lines) {

        ArrayList<ArrayList<String>> valuesInColumns = valuesInColumns(lines);
        ArrayList<String> result = new ArrayList<String>();

        for (int i = 0; i < valuesInColumns.size(); i++) {
            ArrayList<String> values = valuesInColumns.get(i);
            Double max = null;/*  ww w  .  ja  v a2s. c om*/

            for (String value : values) {
                try {

                    Double currentValue = Double.parseDouble(value);

                    if (max == null)
                        max = currentValue;

                    if (max < currentValue)
                        max = currentValue;

                } catch (Exception e) {
                    max = null;
                    break;
                }
            }
            result.add(max + "");
        }

        return result;
    }

    static public ArrayList<ArrayList<String>> valuesInColumns(
            ArrayList<String> lines) {

        ArrayList<ArrayList<String>> valuesInColumns = new ArrayList<ArrayList<String>>();

        for (int row = 0; row < lines.size(); row++) {
            String[] values = lines.get(row).replace("<,>", "<>")
                    .split(",");
            for (int i = 0; i < values.length; i++) {

                if (valuesInColumns.size() <= i) {
                    valuesInColumns.add(new ArrayList<String>());
                }

                valuesInColumns.get(i).add(values[i]);
            }
        }

        return valuesInColumns;
    }
}

Related

  1. getMaxString(ArrayList labels, int currindx)
  2. getMaxValue(ArrayList values)
  3. Max(ArrayList> data)
  4. Max(ArrayList values)
  5. maxEltsInOneSetOfValues(ArrayList values)
  6. maxIntValue(ArrayList ints)
  7. maxLength(ArrayList> a)
  8. maxLengthSurface(ArrayList value)
  9. maxset(ArrayList a)