Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Java equivalent of Python :-1

  1. #1
    Junior Member
    Join Date
    Jul 2021
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Java equivalent of Python :-1

    Hi,

    I have some python code which I am trying to convert into a java equivalent for a project at work and am a little stumped over one bit of code.
    I think its a case of I've been looking at this too long that now I've confused myself entirely and my mind has gone blank. Any assistance would be greatly appreciated.

    Sorry but I don't know how to add tags for python code so I hope this works

    validateID is some function
    empID is a unique ID represented as a string of chars in python
    checkDigit is an arbitrary integer.

    My main issue is the :-1.

    if (validateID(empID[:-1]) != checkDigit):
        .....
        .....

    I basically need to know how to convert that line to a java equivalent.

    Thanks in advance.

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,166
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Java equivalent of Python :-1

    My main issue is the :-1.
    Is there a python forum that can describe what that means?

    Does this help: https://stackoverflow.com/questions/...n-do-in-python
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Jul 2021
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java equivalent of Python :-1

    It is list indexing, it returns all elements [:] except the last one -1.

    For now Im using a loop excluding the last element. Seems to work I guess. Thanks.

Similar Threads

  1. Python to Java
    By programmer123 in forum The Cafe
    Replies: 2
    Last Post: November 30th, 2018, 10:58 AM
  2. Java vs Python
    By Nirali in forum The Cafe
    Replies: 1
    Last Post: July 28th, 2018, 03:45 AM
  3. How to get the java equivalent of C++ const
    By GoodbyeWorld in forum Java Theory & Questions
    Replies: 2
    Last Post: June 12th, 2014, 07:38 AM
  4. java equivalent of the following c# code
    By fzr600 in forum File I/O & Other I/O Streams
    Replies: 2
    Last Post: April 7th, 2012, 05:28 PM
  5. Java equivalent of Python’s struct.pack?
    By thiruvadi.e in forum Java SE APIs
    Replies: 2
    Last Post: July 14th, 2010, 03:09 AM