Java8 group a list of lists to map

I have a Model and a Property class with the following signatures:

public class Property {

    public String name;

    public String getName() {
        return name;

    public void setName(String name) { = name;

public class Model {

    private List<Property> properties = new ArrayList<>();

    public List<Property> getProperties() {
        return properties;

I want a Map<String, Set<Model>> from a List<Model> where the key would be the name from the Property class. How can I can I use java8 streams to group that list by its Properyes’ name? All Propertyes are unique by name.

It is possible to solve in a single stream or should I split it somehow or go for the classical solution?

          .flatMap(model -> model.getProperties().stream()
                  .map(property -> new AbstractMap.SimpleEntry<>(model, property.getName())))

Java: Naming convention for plural acronyms

I know there had already been similar discussions on such naming conventions. However, I’m having problem with plural acronyms.

public List<Disc> findAllDvds(DiscHolder holder) {}
public List<Disc> findAllDvd(DiscHolder holder) {}

Assuming that I have decided to use CamelCase for acronyms, which of the two is generally more acceptable?


I am aware this will invite opinion-based answers, but sometimes when you are in doubt, you just need people to give advises and feedbacks.

To add on, the confusing part here is that findAllDvds can imply a new acronym DVDS, and it can be considered confusing.


The first (findAllDvds). The second (findAllDvd) is simply incorrect, “all” implies more than one, but “Dvd” is singular in English.

Re your edit:

the confusing part here is that findAllDvds can imply a new acronym DVDS, and it can be considered confusing

Since the “all” implies multiple, the “s” on “Dvds” reads as a plural, not part of the acronym. If it really were DVDS, the name would be findAllDvdss or similar.

It’s said that in computer science, there are three hard problems: Cache invalidation, and naming things. (Off-by-one errors are just common, not hard.)

How to extract used byte array from ByteBuffer?

The java.nio.ByteBuffer class has a ByteBuffer.array() method, however this returns an array that is the size of the buffer’s capacity, and not the used capacity. Due to this, I’m having some issues.

I have a ByteBuffer which I am allocating as some size and then I am inserting data to it.

ByteBuffer oldBuffer = ByteBuffer.allocate(SIZE);
addHeader(oldBuffer, pendingItems);
// as of now I am sending everything from oldBuffer
send(address, oldBuffer.array());

How can I just send what is being used in oldBuffer. Is there any one liner to do this?


You can flip the buffer, then create a new array with the remaining size of the buffer and fill it.

byte[] remaining = new byte[oldBuffer.remaining()];

Another way in a one liner with flip() and Arrays.copyOf

Arrays.copyOf(oldBuffer.array(), oldBuffer.remaining());

And without flip()

Arrays.copyOf(oldBuffer.array(), oldBuffer.position());

Also like EJP said, if you have access to the send(..) method, you can add a size and offset argument to the send() method, and avoid the need to create and fill a new array.

Java ArrayList.removeAll(), but for indices

Is there a way to do something like this:


With the ArrayList<Integer> being the indices that I want deleted. I know that I could iterate through the indices list and use remove(index), but I was wondering if there is a one-command way of doing so.

I know how to put this iteration into one line, my question is, if there is a way implemented by oracle.


You can use a Stream to iterate through the indices to remove. However, take care to remove the highest index first, to avoid shifting other elements to remove out of position.

public void removeIndices(List<String> strings, List<Integer> indices)

For removing from a list of Strings this will work, calling the proper remove(int) method. If you were to try this on a List<Integer>, then you will have to avoid calling remove(E) by calling .mapToInt(Integer::intValue) before calling forEach.

Is it a good practice to nullifying String in java

I have a problem with storing a plain password in memory as a String. According to the reference, since Strings are immutable there is a vulnerability of using String data type for sensitive data storing in memory.

Why is char[] preferred over String for passwords?

Can I overcome this security issue by nullifying the string variable instead of using char array or String buffer/builder.

eg : String password=”password”;
password = null;


No. Nullifying a string would only delink the reference. But the value will still exist in string pool. Because to conserve memory, string values are retained in the string pool.

Any potential hacker, can retrieve the value by gaining access to the string pool.

Whereas, using char[], you can simply treat that object as any other object. And nullifying the char object will wipe off the data from heap at the time of garbage collection.

An even better option will be using a byte array.

Read more about String Constant pool.

Java ArrayList, how to ignore a value from the object when using contains()

I have a class like that:

public class Student implements Serializable{
  private String name;
  private int age;
  private Image img;

I store a few students in an ArrayList and write them to a file. When I restart the application I load them from that file again. However, the Image img variable is constantly changing. That means when I use arrayList.contains(studentA) it’s not the same object anymore, so arrayList.remove(studentA) won’t work.

Is there an easy way to either: Only check for the name of the student or ignore the Image field when using contains()?



Just implement the equals/hashcode without the Image attribute.

public class Student implements Serializable {

    private String name;
    private int age;
    private Image img;

    public boolean equals(final Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Student student = (Student) o;
        return age == student.age &&

    public int hashCode() {

        return Objects.hash(name, age);


screen-recorder do not find pom.xml on artifacory

I want use screen-recorder via Maven.


I have more one repository:


When I have my Maven setting.xml is it OK for me, but for other people is it KO.

21:30:45 Downloading:
[INFO] ------------------------------------------------------------------------
16:30:54 [INFO] ------------------------------------------------------------------------
21:30:54 [ERROR] Failed to execute goal on project foo: Could not resolve dependencies for project com.comp:foo:jar:0.0.1-SNAPSHOT: Failed to collect dependencies at com.github.fii:fuu:jar:1.1.0 -> org.monte:screen-recorder:jar:0.7.7: Failed to read artifact descriptor for org.monte:screen-recorder:jar:0.7.7: Could not transfer artifact org.monte:screen-recorder:pom:0.7.7 from/to ( Not authorized , ReasonPhrase:Authorization Required. -> [Help 1] do not return a real 404:

      "errors" : [ {
        "status" : 404,
        "message" : "File not found."
      } ]

My build crashes because it tries to go to the Oracle repository but I would like this to load the jar file which is on

how can I configure this?


Your build crashes, because it’s trying to download pom (metadata file) for the artifact:

Could not transfer artifact org.monte:screen-recorder:pom:0.7.7

which is not located in the repository (only the .jar file resides there).

I would recommend manually downloading the artifact from

and installing it in your local repository.