Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import android.location.Address;

import android.support.annotation.Nullable;

public class Main {
    public static @Nullable String getAddressStringOneLine(@Nullable final Address address) {

        if (address == null) {
            return null;
        }

        final StringBuilder sb = new StringBuilder(address.getAddressLine(0));
        if (address.getMaxAddressLineIndex() >= 1) {
            for (int i = 1; i <= address.getMaxAddressLineIndex(); i++) {

                if (address.getAddressLine(i).equalsIgnoreCase(address.getCountryName())) {
                    continue;
                }

                sb.append(',');
                sb.append(' ');
                sb.append(address.getAddressLine(i));
            }
        }

        return sb.toString();
    }
}