Testdome Java Questions And Answers May 2026

import java.util.*; public class MergeNames public static String[] uniqueNames(String[] arr1, String[] arr2) // Guard against null inputs if (arr1 == null && arr2 == null) return new String[0];

// Split on whitespace, but also remove punctuation String[] words = text.toLowerCase().split("[\\s\\pPunct]+"); int totalLetters = 0; int wordCount = 0; for (String word : words) if (word.isEmpty()) continue; // Count only a-z letters int letters = word.replaceAll("[^a-z]", "").length(); if (letters > 0) totalLetters += letters; wordCount++; if (wordCount == 0) return 0.0; double average = (double) totalLetters / wordCount; // Round to 2 decimals DecimalFormat df = new DecimalFormat("#.##"); return Double.parseDouble(df.format(average)); testdome java questions and answers

public void attachWagonFromLeft(int wagonId) deque.addFirst(wagonId); import java

This is TestDome's favorite object-oriented design question. It checks whether you understand tight coupling vs. loose coupling. class AlertService private MapAlertDAO storage = new MapAlertDAO(); // Hard dependency // ... DELETE class User Set&lt

// Given a list of permissions (READ, WRITE, DELETE), return true if user can perform action enum Permission READ, WRITE, DELETE class User Set<Permission> permissions; public boolean can(Permission p) ...

// Step 3: Inject via constructor class AlertService private final AlertDAO storage;

try riskyOperation(); catch (IllegalArgumentException e) return defaultValue; // Or log, but TestDome has no logger