Here you can find the source of filterDataList(JList jList, List dataList, String text)
public static void filterDataList(JList jList, List dataList, String text)
//package com.java2s; //License from project: Open Source License import java.util.ArrayList; import java.util.List; import javax.swing.JList; public class Main { public static void filterDataList(JList jList, List dataList, String text) { jList.setListData(new Object[] {}); List newList = new ArrayList(); dataList.stream().filter((ob) -> (ob.toString().toLowerCase().startsWith(text.toLowerCase()))) .forEach((ob) -> {/*from w w w. j av a2s.c o m*/ newList.add(ob); }); jList.setListData(newList.toArray()); } }