question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

splitToList should return ImmutableList

See original GitHub issue

I find myself constantly writing things like this:

ImmutableList<String> parts = ImmutableList.copyOf(Splitter.on("/").split(path));

I’d like to use splitToList but it doesn’t return an immutable list.

I was wondering how the Guava team justifies this method returning a mutable list. What’s the use case for this list being mutable?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
hakanaicommented, Dec 3, 2019

(Or as a good enough second option, can we at least get splitToImmutableList as an alternative?)

0reactions
hakanaicommented, Dec 4, 2019

I’m afraid I’ll probably be making a BetterSplitter class which just has the method return the right list type in the first place and banning use of Guava’s one in our codebase.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Splitter (Guava: Google Core Libraries for Java 19.0 API)
Splits sequence into string components and returns them as an immutable list. Splitter · trimResults(). Returns a splitter that behaves equivalently to this ......
Read more >
Splitter splitToList() method | Guava | Java - GeeksforGeeks
The method splitToList(CharSequence sequence) splits sequence into string components and returns them as an immutable list. Syntax:.
Read more >
Example usage for com.google.common.base Splitter splitToList
@CheckReturnValue @Beta public List<String> splitToList(CharSequence ... Splits sequence into string components and returns them as an immutable list.
Read more >
Why does List.of() in Java not return a typed immutable list?
elements) should return a ImmutableList that extends List . This way the user can decide if he cares to show this fact of...
Read more >
com.google.common.base.Splitter.onPattern java code ...
splitToList is @Beta, so we avoid it. return ImmutableList. ... <p>Note: There will be a trailing empty string if the input string ends...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found