Code example for StringBuilder

Methods: StringBuilder.append, append, toString

0
  public String longDate() {
    return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
  } 
 
  public String longLog() {
    StringBuilder sb = new StringBuilder();
    Location loc = mWatcher.getLocation();
    SignalStrength ss = mWatcher.getSignalStrength();
 
    sb.append(longDate());
    sb.append(" ");
 
    if(loc != null) {
      sb.append(String.format(Locale.US, "Lat %.6f Lng %.6f", loc.getLatitude(), loc.getLongitude()));
 
      if(loc.hasAltitude()) 
        sb.append(String.format(Locale.US, " Alt %.2f", loc.getAltitude()));
 
      if(loc.hasAccuracy()) 
        sb.append(String.format(Locale.US, " Acc %.2f", loc.getAccuracy()));
 
      if(loc.hasBearing()) 
        sb.append(String.format(Locale.US, " Brg %.1f", loc.getBearing()));
 
      if(loc.hasSpeed()) 
        sb.append(String.format(Locale.US, " Spd %.2f", loc.getSpeed()));
    } else { 
      sb.append("Location unknown");
    } 
    sb.append(" ");
 
    if(ss != null) {
      sb.append(String.format(Locale.US, "GSM %d", ss.getGsmSignalStrength()));
    } else { 
      sb.append("Signal unknown");
    } 
    sb.append(" ");
 
    if(mWatcher.hasBatteryState()) {
      sb.append(String.format(Locale.US, "BtL %.2f BtH %s BtT %d",
            mWatcher.batteryLevel(),
            mWatcher.batteryHealth(),
            mWatcher.batteryTemperature()
          )); 
    } else { 
      sb.append("Battery unknown");
    } 
    sb.append(" ");
 
    return sb.toString();
  } 
 
  public String shortLog() {
    StringBuilder sb = new StringBuilder();
    Location loc = mWatcher.getLocation();