Question: Am trying to get the difference between two files even though the file looks same it shows the difference that it has empty lines in the beginning 

How can I remove the empty lines before doing the difference 

I know sed -i '/^$/d should work but it didn't worked for me is there any other way 

Thanks

Answer: 
[This answer](https://stackoverflow.com/a/23276455/2711488) already provides a solution which creates a `Stream` out of an `Enumeration`:

> 
> 
> ```
>  public static <T> Stream<T> enumerationAsStream(Enumeration<T> e) {
>      return StreamSupport.stream(
>          Spliterators.spliteratorUnknownSize(
>              new Iterator<T>() {
>                  public T next() {
>                      return e.nextElement();
>                  }
>                  public boolean hasNext() {
>                      return e.hasMoreElements();
>                  }
>              },
>              Spliterator.ORDERED), false);
>  }
> 
> ```
> 
> 

It should be emphasized that the resulting `Stream` *is* as lazy as any other `Stream`, as it won’t process any items before the terminal action has been commenced and if the terminal operation is short-circuiting, it will iterate only as many items as necessary.

Still, it has room for improvement. I’d always add a `forEachRemaining` method when there is a straight-forward way to process all elements. Said method will be called by the `Stream` implementation for most non-short-circuiting operations:

```
public static <T> Stream<T> enumerationAsStream(Enumeration<T> e) {
    return StreamSupport.stream(
        Spliterators.spliteratorUnknownSize(
            new Iterator<T>() {
                public T next() {
                    return e.nextElement();
                }
                public boolean hasNext() {
                    return e.hasMoreElements();
                }
                public void forEachRemaining(Consumer<? super T> action) {
                    while(e.hasMoreElements()) action.accept(e.nextElement());
                }
            },
            Spliterator.ORDERED), false);
}

```

However, the code above is a victim of the “using `Iterator` because it’s so familiar” antipattern. The created `Iterator` will get wrapped into an implementation of the new `Spliterator` interface and provides no advantage over implementing `Spliterator` directly:

```
public static <T> Stream<T> enumerationAsStream(Enumeration<T> e) {
    return StreamSupport.stream(
        new Spliterators.AbstractSpliterator<T>(Long.MAX_VALUE, Spliterator.ORDERED) {
            public boolean tryAdvance(Consumer<? super T> action) {
                if(e.hasMoreElements()) {
                    action.accept(e.nextElement());
                    return true;
                }
                return false;
            }
            public void forEachRemaining(Consumer<? super T> action) {
                while(e.hasMoreElements()) action.accept(e.nextElement());
            }
    }, false);
}

```

On the source code level, this implementation is as simple as the `Iterator`-based, but eliminates the delegation from a `Spliterator` to an `Iterator`. It only requires its readers to learn about the new API.
In my [StreamEx](https://github.com/amaembo/streamex) library there's simple method [`StreamEx.of(Enumeration)`](http://amaembo.github.io/streamex/javadoc/one/util/streamex/StreamEx.html#of-java.util.Enumeration-) which does the job:

```
Stream<String> stream = StreamEx.of(enumeration);

```

Note that it not just a shortcut to the @Holger solution, but implemented in different manner. In particular, it has significantly better parallel execution characteristics compared to solutions involving `Spliterators.spliteratorUnknownSize()`.