相关疑难解决方法(0)

如何在Java中舍入整数除法并得到int结果?

我只是写了一个小方法来计算手机短信的页数.我没有选择使用Math.ceil,老实说它似乎非常难看.

这是我的代码:

public class Main {

/**
 * @param args the command line arguments
 */
public static void main(String[] args) {
   String message = "today we stumbled upon a huge performance leak while optimizing a raycasting algorithm. Much to our surprise, the Math.floor() method took almost half of the calculation time: 3 floor operations took the same amount of time as one trilinear interpolation. Since we could not belive that the floor-method could produce such a enourmous overhead, …
Run Code Online (Sandbox Code Playgroud)

java math formatting types

81
推荐指数
6
解决办法
11万
查看次数

将列表拆分为多个列表,在java 8中具有固定数量的元素

我想要一些类似于scala分组函数的东西.基本上,一次挑选2个元素并处理它们.以下是相同的参考:

将列表拆分为具有固定数量元素的多个列表

Lambdas确实提供了诸如groupingBy和partitioningBy之类的东西,但它们似乎都没有像Scala中的分组函数那样做.任何指针将不胜感激.

java scala java-8

12
推荐指数
2
解决办法
1万
查看次数

使用Java 8 Streams的Spring Data JPA存储库

假设我有以下存储库:

public interface UserRepository extends JpaRepository<User, Long> {

    @Query("select u from User u")
    Stream<User> streamAllPaged(Pageable pageable);
}
Run Code Online (Sandbox Code Playgroud)

我想进行搜索:

public Page<User> findAllUsers(Pageable page) {

    Page<User> page = null;
    try (Stream<User> users = userRepository.streamAllPaged(page)) {
            Set<User> users = users.filter(u -> user.getName().equals("foo"))
                    .collect(Collectors.toSet());
            //create page from set?
    }

}
Run Code Online (Sandbox Code Playgroud)

显然我可以使用子列表并手动插入页面大小等但我想应该有更"标准"的方法来做到这一点?

java spring java-8 spring-data spring-data-jpa

9
推荐指数
1
解决办法
3940
查看次数

标签 统计

java ×3

java-8 ×2

formatting ×1

math ×1

scala ×1

spring ×1

spring-data ×1

spring-data-jpa ×1

types ×1