Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7007039
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:33:20+00:00 2026-05-27T21:33:20+00:00

I have an ArrayList called account which contains Strings. I’m trying to write a

  • 0

I have an ArrayList called account which contains Strings. I’m trying to write a method that checks if they are in order and returns true or false based on whether they are in order or not.

How would you go about this? I’ve already tried checking the initial chracter with a for-loop but it went terribly wrong. I created a new ArrayList and set it equal to the original, then sorted it and compared them but since they contained the same data it always came back true.

Just an extra quick question, since I’m doing this for Strings, how would you check if some numbers were in ascending/descending order? Throught the same principal?

Thankyou!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T21:33:21+00:00Added an answer on May 27, 2026 at 9:33 pm

    Try this (assuming you want to compare the strings using their natural ordering, of course):

    String previous = ""; // empty string: guaranteed to be less than or equal to any other
    
    for (final String current: thelist) {
        if (current.compareTo(previous) < 0)
            return false;
        previous = current;
    }
    
    return true;
    

    This is due to the fact that String implements Comparable<String>, and the comparison will be done using the strings’ natural ordering.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an arraylist that contains items called Room. Each Room has a roomtype
I have a driver class called Advantech which is stored inside an ArrayList .
I have a method which returns an ArrayList of phrases to be used as
So let's say I have an ArrayList of Strings, called list1, containing the strings,
Basically, I have a Container class called Employees which has in it an ArrayList.
I have some questions as to which overloaded method would be called in certain
I have an ArrayList<String> that I'd like to return a copy of. ArrayList has
I have an ArrayList<String> , and I want to remove repeated strings from it.
I have an arraylist that gets different type of values in it, 1st value->
I have an arraylist which has a class datastructure. public class empRec { public

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.