Java List First Item getFirstAsString(Map> multiValueMap, String key)

Here you can find the source of getFirstAsString(Map> multiValueMap, String key)

Description

get First As String

License

Open Source License

Declaration

public static <T> String getFirstAsString(Map<String, List<T>> multiValueMap, String key) 

Method Source Code

//package com.java2s;

import java.util.*;

public class Main {
    public static <T> String getFirstAsString(Map<String, List<T>> multiValueMap, String key) {
        return getFirstAsString(multiValueMap, key, false);
    }//w ww.  j  ava  2s.co m

    public static <T> String getFirstAsString(Map<String, List<T>> multiValueMap, String key, boolean stripQuotes) {
        List<T> values = multiValueMap.get(key);
        if (values == null || values.isEmpty())
            return null;
        Object value = values.get(0);
        if (value == null)
            return null;
        return stripQuotes ? stripQuotes(value.toString()) : value.toString();
    }

    public static String stripQuotes(String value) {
        if (value == null)
            return null;
        int start = 0, end = value.length();
        if (value.charAt(0) == '"')
            start = 1;
        if (value.charAt(value.length() - 1) == '"')
            end = value.length() - 1;
        return value.substring(start, end);
    }
}

Related

  1. getFirst(List c)
  2. getFirst(List l)
  3. getFirst(List list)
  4. getFirst(List list)
  5. getFirst(List source)
  6. getFirstColumn(List> llo, String reason)
  7. getFirstDuplicateValue(List values)
  8. getFirstElement(List list)
  9. getFirstElement(List collection)