• Intro Headers Instructions Macros Commands
Fork me on GitHub
    • Getting Started
      • Introduction
      • How to install bnd
      • Guided Tour Workspace & Projects
      • bnd / bndlib Features and JAR Wrapping Techniques
      • FAQ - Frequently Asked Questions
    • Concepts and Practices
      • Concepts
      • Background
      • Best practices
    • Build and Development
      • Build
      • Generating JARs
      • Versioning
      • Baselining
      • Service Components
      • Metatype
      • Contracts
      • Bundle Annotations
      • Accessor Properties
      • SPI Annotations
    • Dependency and Launching
      • Resolving Dependencies
      • Launching
      • Startlevels
    • Testing
      • Testing
      • Testing with Launchpad
    • Packaging and Distribution
      • Packaging Applications
      • JPMS Libraries
      • Wrapping Libraries to OSGi Bundles
    • Documentation and Tools
      • Generating Documentation
      • bnd CLI Commands
      • For Developers
      • Templates for Workspaces
      • Tips for Windows users
      • Tools bound to bnd
    • Reference Material
      • Reference
      • Headers
      • Instruction Reference
      • Instruction Index
      • Macro Reference
      • Macro Index
      • Plugins
      • External Plugins
    • Configuration and Troubleshooting
      • Settings
      • Errors
      • Warnings
  • sublist ';' START ';' END (';' LIST )*

    Prev Next
    Macro
    Extract a portion of a list with support for negative indices

    Summary

    The sublist macro extracts elements from a list between start and end positions. It supports negative indices to count from the end of the list.

    Syntax

    ${sublist;<start>;<end>;<list>[;<list>...]}
    

    Parameters

    • start - Starting index (0-based, negative counts from end)
    • end - Ending index (exclusive, negative counts from end)
    • list - One or more lists to combine and extract from

    Behavior

    • Combines all provided lists
    • Extracts elements from start (inclusive) to end (exclusive)
    • Negative indices count from the end
    • If start > end, they are automatically swapped
    • Returns comma-separated sublist

    Examples

    Get first 3 elements:

    ${sublist;0;3;apple,banana,cherry,date,elderberry}
    # Returns: "apple,banana,cherry"
    

    Get last 2 elements:

    ${sublist;-2;-0;apple,banana,cherry}
    # Returns: "banana,cherry"
    

    Skip first element:

    ${sublist;1;-0;red,green,blue}
    # Returns: "green,blue"
    

    Get middle elements:

    ${sublist;2;5;a,b,c,d,e,f,g}
    # Returns: "c,d,e"
    

    Extract from multiple lists:

    ${sublist;0;3;one,two;three,four,five}
    # Returns: "one,two,three"
    

    Use Cases

    • Extracting ranges from lists
    • Pagination of results
    • Removing headers or trailers
    • List slicing operations
    • Selecting specific segments
    • Windowing over lists

    Notes

    • Indices are 0-based (first element is 0)
    • Negative indices count backwards (-1 adjusts to list end)
    • End index is exclusive (not included in result)
    • Start and end are swapped if start > end
    • Combines multiple list arguments first
    • See also: ${first}, ${last}, ${get} for single elements

    See test cases in MacroTestsForDocsExamples.java

Prev Next
Search
    • Home