Java List Truncate truncateStringList(List strings, String truncateFrom)

Here you can find the source of truncateStringList(List strings, String truncateFrom)

Description

Removes all entries in the list after truncateFrom string (inclusive truncateFrom entry)

License

Open Source License

Parameter

Parameter Description
strings list of strings to truncate
truncateFrom a parameter

Return

updated list

Declaration

static public List<String> truncateStringList(List<String> strings, String truncateFrom) 

Method Source Code

//package com.java2s;
/*******************************************************************************
* Copyright (c) 2015 ARM Ltd. and others
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:// w ww  .  j  a va 2 s . c o m
* ARM Ltd and ARM Germany GmbH - Initial API and implementation
*******************************************************************************/

import java.util.List;

public class Main {
    /**
     * Removes all entries in the list after truncateFrom string (inclusive truncateFrom entry) 
     * @param strings list of strings to truncate
     * @param truncateFrom
     * @return updated list
     */
    static public List<String> truncateStringList(List<String> strings, String truncateFrom) {
        if (strings == null)
            return null;
        int index = strings.indexOf(truncateFrom);
        if (index >= 0)
            return strings.subList(0, index);
        return strings;
    }
}

Related

  1. truncateEnd(List list, int numElements)
  2. truncateList(final List full, int maxSize)
  3. truncateList(int offset, int count, List originalList)
  4. truncateList(List input, int maxSize)
  5. truncateList(List list, int len)
  6. truncateVersionFromModFileName(List fileNames)