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 2 of 2

Thread: Java String[]

  1. #1
    Junior Member
    Join Date
    Nov 2020
    Posts
    15
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Lightbulb Java String[]

    String[] string1={"A","B","C"};
    String[] string2={"A","D"};

    Hi im doing project in Java JDA and want to ask when i have this type of code and want to do boolean if something from string2 is in string1 it will return true.

    I tried boolean B1=string2.equals(string1.length); but it dont work, in warnings was that '.equals' should be 'Array.equals' but when i tried change it dont want to compile project.
    Any help please?

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Java String[]

    boolean B1=string2.equals(string1.length);
    string2 is an array. Use the Arrays class's equals method to compare two arrays. See the API doc for the Arrays class for how to use that method.
    The API doc: https://docs.oracle.com/javase/8/docs/api/index.html
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Java String regex - Extract String Tag for its Value
    By Raj4Smile in forum What's Wrong With My Code?
    Replies: 0
    Last Post: May 12th, 2014, 08:47 AM
  2. [SOLVED] How to modify core Java interface java.sql.Statement.execute(String sql)?
    By amughost in forum Java Theory & Questions
    Replies: 6
    Last Post: June 9th, 2012, 04:31 PM
  3. Replies: 1
    Last Post: April 19th, 2012, 02:46 AM
  4. Java Error cannot be applied to (java.lang.String), phone book entry program.
    By iceyferrara in forum What's Wrong With My Code?
    Replies: 5
    Last Post: September 23rd, 2011, 06:32 AM
  5. Replies: 2
    Last Post: November 3rd, 2009, 06:28 AM