Skip to content

Instantly share code, notes, and snippets.

@isicju
Created July 9, 2023 14:59
Show Gist options
  • Save isicju/54060ff9468f865211f78beaa777abb4 to your computer and use it in GitHub Desktop.
Save isicju/54060ff9468f865211f78beaa777abb4 to your computer and use it in GitHub Desktop.
public class Main {
public static void main(String[] args) throws InterruptedException {
System.out.println("Works");
}
}
@LeonidKarlovskiy
Copy link

public static Map<String, User> findLowIncomeCitizens(ArrayList users) {
return users.stream()
.filter(user -> user.getCity().equals("New York") && user.getSalary() < 100L)
.collect(Collectors.toMap(User::getGuid, Function.identity()));
}

public static Country findCountryByName(DataSource dataSource, String countryName) throws SQLException {
try (Connection connection = dataSource.getConnection();
PreparedStatement statement = connection.prepareStatement("SELECT * FROM countries WHERE name = ?")) {
statement.setString(1, countryName);
try (ResultSet resultSet = statement.executeQuery()) {
if (resultSet.next()) {
return new Country(countryName, resultSet.getString("region"));
}
}
} catch (SQLException e) {
return null;
}
return null;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment