Ok, what I want to know is is there a way with Java to do what Python can do below...
string_sample = \"hello world\"
string_sample[:-1]
>>> \"hell
use substring
:
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
String s = new String("hello world");
System.out.println(s.substring(0, s.length()));
System.out.println(s.substring(s.length() - 1, s.length()));
System.out.println(s.substring(3, 4));
}
}
or charAt
:
System.out.println(s.charAt(s.length() - 1));
System.out.println(s.charAt(3));
Java is not python so negative index should be avoided to maintain constancy. However, you could make a simple conversion function.