<div dir="ltr"><div class="gmail_default" style="font-family:monospace">Thanks for the response <a class="gmail_plusreply" id="plusReplyChip-0" href="mailto:stuart.marks@oracle.com" tabindex="-1">@Stuart Marks</a>!</div><div class="gmail_default" style="font-family:monospace"><br></div><div class="gmail_default" style="font-family:monospace">> A third concern is that people come along and ask whether we can</div><div class="gmail_default" style="font-family:monospace">> have something in Java that's rather like Python's slices.</div><div class="gmail_default" style="font-family:monospace"><br></div><div class="gmail_default" style="font-family:monospace">Hah, this email started out as a request for Python slices lol. But I came to the same conclusion as you.</div><div class="gmail_default" style="font-family:monospace"><br></div><div class="gmail_default" style="font-family:monospace">I am quite curious about what Project Amber has to say about this. Range patterns, for example.</div><div class="gmail_default" style="font-family:monospace"><br></div><div class="gmail_default" style="font-family:monospace">> You had asked about List, not String, but I think similar issues apply.</div><div class="gmail_default" style="font-family:monospace">> I'd guess that String and substring operations are a lot more frequent</div><div class="gmail_default" style="font-family:monospace">> than subList operations. But maybe you have some subList use cases in</div><div class="gmail_default" style="font-family:monospace">> mind. Could you give more details about what you're thinking of?<span class="gmail-im"><br></span></div><div class="gmail_default" style="font-family:monospace"><span class="gmail-im"><br></span></div><div class="gmail_default" style="font-family:monospace"><span class="gmail-im">I definitely agree that there is heavy overlap in the problem spaces of subList and substring.</span></div><div class="gmail_default" style="font-family:monospace"><span class="gmail-im"><br></span></div><div class="gmail_default" style="font-family:monospace"><span class="gmail-im">As for use cases, mostly Path-Finding algorithms and <a href="https://en.wikipedia.org/wiki/Natural_language_processing">NLP</a> work. The PFA is mostly self explanatory, but for NLP, I splice up Strings in a bunch of different ways. You have to cycle through different permutations of word groupings to anchor a phrase to a concept (so I get to use both substring and subList lol). And each concept has an associated type for it -- a permitted subtype of a sealed type (which may itself be another permitted subtype of another).</span></div><div class="gmail_default" style="font-family:monospace"><span class="gmail-im"><br></span></div><div class="gmail_default" style="font-family:monospace"><span class="gmail-im">Since most of this is me trimming from the front or end, it became way more manageable to make headList and subList for myself. So, I think that they could be useful for others too.</span></div><div class="gmail_default" style="font-family:monospace"><span class="gmail-im"><br></span></div><div class="gmail_default" style="font-family:monospace"><span class="gmail-im">I will say -- zooming out (while thinking of the substring/subList duality), String and List are just Sequences of X. Maybe there is value in making something more broad here? Maybe some Sequence-like interface where we expose some helpful range methods? It would all devolve to the statement forms you mentioned earlier. And in an ideal world, Project Amber could latch onto that if/when range patterns go live. I remember watching this video by Brian Goetz about <a href="https://www.youtube.com/watch?v=Gz7Or9C0TpM">Growing the Language</a>. It kind of feels like an interface like this would be very amenable, though I might also be thinking too far ahead lol.</span></div></div><br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">On Wed, Nov 19, 2025 at 12:48 AM Stuart Marks <<a href="mailto:stuart.marks@oracle.com">stuart.marks@oracle.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br>
<br>
On 11/16/25 10:51 AM, David Alayachew wrote:<br>
> Could we add headList(int) and tailList(int) to j.u.List? I searched JBS and found <br>
> nothing.<br>
> <br>
> It's commonly what people want when doing subList(int, int), so this should be <br>
> pretty well received.<br>
<br>
Maybe. :-)<br>
<br>
There's a nexus of diffuse concerns here.<br>
<br>
One concern is subranges of things in general, such as Strings, CharSequences, <br>
Lists, and arrays. Subranges are all expressed as methods with (start, end) <br>
parameters. These are powerful enough to do anything you need to do, but they're <br>
sometimes inconvenient.<br>
<br>
One reason these can be inconvenient is related to the second concern, which is that <br>
sometimes the APIs require the creation of a local variable, which in turn forces an <br>
expression to turn into a statement. For example, consider a task of getting a <br>
String from somewhere, taking the first three characters, and passing that elsewhere <br>
to perform further work. One can write that as<br>
<br>
furtherWork(getString().substring(0, 3));<br>
<br>
But if you want to take the *last* three characters and pass them along, you have to <br>
do this:<br>
<br>
var tmp = getString();<br>
furtherWork(tmp.substring(tmp.length() - 3));<br>
<br>
This isn't terrible, but sometimes it disrupts an expression to declare a local <br>
variable.<br>
<br>
At least there is a one-arg substring method that takes characters to the end of the <br>
string. If this method weren't there, you'd have to call length() twice (or store <br>
the length in another local variable). Again, not terrible, but yet another thing <br>
that adds friction.<br>
<br>
A third concern is that people come along and ask whether we can have something in <br>
Java that's rather like Python's slices. For a variety of reasons I don't think we <br>
should accept negative indexes or step values other than 1, but there are some <br>
things that probably occur frequently. For example, to get the last three characters <br>
of a string, one can write s[-3:]. That's pretty nice.<br>
<br>
You had asked about List, not String, but I think similar issues apply. I'd guess <br>
that String and substring operations are a lot more frequent than subList <br>
operations. But maybe you have some subList use cases in mind. Could you give more <br>
details about what you're thinking of?<br>
<br>
> In that case, would be nice if we could add an entry to JBS with a Won't Fix, to <br>
> make it easier for those looking to see why not. Maybe even link this thread for <br>
> further reading.<br>
<br>
Heh, yeah I've done that a couple times -- filed a bug just to close it out with an <br>
explanation why. I was wondering whether anybody would find that useful. I think <br>
this topic is worth some discussion, though, so I won't do that quite yet. :-)<br>
<br>
s'marks<br>
<br>
</blockquote></div>