本文整理汇总了Java中java.util.ArrayList.removeIf方法的典型用法代码示例。如果您正苦于以下问题:Java ArrayList.removeIf方法的具体用法?Java ArrayList.removeIf怎么用?Java ArrayList.removeIf使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.ArrayList
的用法示例。
在下文中一共展示了ArrayList.removeIf方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import java.util.ArrayList; //导入方法依赖的package包/类
public static void main(String[] args) {
ArrayList<String> list = new ArrayList<>(Arrays.asList("I", "love", "you", "too"));
list.removeIf(new Predicate<String>() {
@Override
public boolean test(String s) {
if (s.length() < 2) {
return true;
}
return false;
}
});
list.removeIf(l -> l.length() < 4);
System.out.println(JSON.toJSONString(list));
Date date = new Date();
ConcurrentHashMap concurrentHashMap = new ConcurrentHashMap<>();
concurrentHashMap.put("ds", 1);
concurrentHashMap.computeIfAbsent("fdfd", k -> k.toString());
System.out.println(JSON.toJSONString(concurrentHashMap));
HashMap hashMap = new HashMap<>();
hashMap.put("fd1", 1);
hashMap.put("fd2", 1);
hashMap.put("fd3", 1);
hashMap.put("fd4", "fd");
hashMap.put("fd5", 1);
hashMap.entrySet().stream().forEach(hash -> {
System.out.println(hash.toString());
});
}
示例2: getRecipeSlots
import java.util.ArrayList; //导入方法依赖的package包/类
@Override
public List<Slot> getRecipeSlots(ContainerGui container)
{
ArrayList<Slot> slots = Lists.newArrayList(container.getSlotsForSource(moduleName));
slots.removeIf(slot -> slot.getSlotIndex() >= inputSlots);
return slots;
}
示例3: getPrivateChatsByTraveler
import java.util.ArrayList; //导入方法依赖的package包/类
/**
* Get all private chat rooms of a traveler
*
* @param travelerId int
* @return List<ChatRoom>
*/
@RequestMapping(path = "/api/private-chats/list/{travelerId}", method = RequestMethod.GET)
public List<ChatRoom> getPrivateChatsByTraveler(@PathVariable int travelerId) {
ArrayList<ChatRoom> rooms = chatRoomRepository.getByTravelerId(travelerId);
rooms.removeIf(c -> !c.isPrivate());
return rooms;
}
示例4: getPublicChatsByTraveler
import java.util.ArrayList; //导入方法依赖的package包/类
/**
* Get all publich chat rooms of a traveler
*
* @param travelerId int
* @return List<ChatRoom>
*/
@RequestMapping(path = "/api/public-chats/list/{travelerId}", method = RequestMethod.GET)
public List<ChatRoom> getPublicChatsByTraveler(@PathVariable int travelerId) {
ArrayList<ChatRoom> rooms = chatRoomRepository.getByTravelerId(travelerId);
rooms.removeIf(ChatRoom::isPrivate);
return rooms;
}
示例5: apply
import java.util.ArrayList; //导入方法依赖的package包/类
/**
<hr>
<h2>Applies this Rule on the Context param</h2>
<h3>
— A Person that didn't reach minium age can't get in couple <br>
— A Person that already is in couple, can't get in couple with someone else <br>
— 2 People have to <code>match</code> to get in couple <br>
See {@link CoupleRule#isMatch(Person, Person)}</h3>
<hr>
<h3>
Created : Alexandre Bolot 10/01 <br>
Modified : Alexandre Bolot 14/01
</h3>
<hr>
@param context Context to apply this rule onto
*/
@Contract ("null -> fail")
public void apply (@NotNull Context context)
{
//region --> Check params
if (context == null) throw new IllegalArgumentException("Contect param is null");
//endregion
ArrayList<Person> tmpPeople = new ArrayList<>(context.people());
if (minimumAge != anyAge) tmpPeople.removeIf(person -> person.data().age() < minimumAge);
tmpPeople.removeIf(person -> context.relations().stream().anyMatch(relation -> relation.involves(person)));
for (Person person1 : tmpPeople)
{
for (Person person2 : tmpPeople)
{
if (person2.equals(person1)) continue;
if (context.relations().contains(relation -> relation.involves(person1))) continue;
if (context.relations().contains(relation -> relation.involves(person2))) continue;
if (isMatch(person1, person2))
{
context.relations().add(new Relation(person1, person2, Couple, currentTime()));
break;
}
}
}
}
示例6: enableOn
import java.util.ArrayList; //导入方法依赖的package包/类
/**
* Call this method to re-enable an Activity previously disabled with {@link #disableOn(Class)}.
* @param activityClass The Activity class
* @see #disableOn(Class)
*/
public void enableOn(Class<? extends Activity> activityClass) {
ArrayList<Class<? extends Activity>> disabledActivities = this._DisabledActivities;
if(disabledActivities != null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
disabledActivities.removeIf(c -> c == activityClass);
} else {
disabledActivities.remove(activityClass);
}
}
}