今日已更新 329 条资讯 | 累计 24286 条内容
关于我们

开发者

编程技术、框架工具、最佳实践

6725
篇文章

共 6725 篇 · 第 65/337 页

Dev.to

Conditional Operator (`?:`) in Java

The conditional operator ( ?: ) — The Only Ternary Operator is one of the most useful operators in Java. It lets you write simple decision-making logic in a single line, making your code cleaner and more concise. It's also a favorite topic in Java interviews because of its syntax, nesting behavior, and type compatibility rules. In this article, you'll learn: What the conditional operator is Why it's called a ternary operator Syntax and working Nested conditional operators Difference between ?: and if-else Practical examples Interview questions Memory tricks What is the Conditional Operator? The conditional operator is represented by: ? : It is the only ternary operator in Java . A ternary operator takes three operands , unlike: Operator Type Number of Operands Example Unary 1 ++x , !flag , ~5 Binary 2 a + b , a > b , a && b Ternary 3 (a > b) ? a : b Syntax result = ( condition ) ? valueIfTrue : valueIfFalse ; How It Works condition │ Is it true? / \ Yes No │ │ valueIfTrue valueIfFalse │ │ └────── Result ──────┘ If the condition is true , Java returns the value before the colon ( : ). If the condition is false , Java returns the value after the colon ( : ). Example 1 int x = ( 10 > 20 ) ? 30 : 40 ; System . out . println ( x ); Output 40 Step-by-Step Evaluate the condition: 10 > 20 ↓ false Since the condition is false, Java selects the value after : . 40 Therefore, x = 40 Example 2: Finding the Maximum int a = 10 ; int b = 20 ; int max = ( a > b ) ? a : b ; System . out . println ( max ); Output 20 This is one of the most common uses of the conditional operator. Example 3: Even or Odd int number = 7 ; String result = ( number % 2 == 0 ) ? "Even" : "Odd" ; System . out . println ( result ); Output Odd Example 4: Absolute Value int x = - 5 ; int absolute = ( x < 0 ) ? - x : x ; System . out . println ( absolute ); Output 5 Nested Conditional Operators One of the biggest advantages of the conditional operator is that it can be nested . Example int x = ( 10 > 20 ) ? 30 :

Rajesh Bhola 2026-07-14 23:41 👁 7 查看原文 →
HackerNews

Show HN: Opening lines of famous literary works

This came from an idea that had been knocking around in my head for several years. I had been collecting opening lines of famous works and thought it would be cool to see one everyday as I opened the browser. I tried different styles but landed on the simple background with the text, let the words speak for themselves. Over time i've added more quotes I believe now there are close to 60, so hopefully you can refresh a few times and get a fresh one every time. I hope you guys like it, enjoy!

plicerin 2026-07-14 23:24 👁 5 查看原文 →
Dev.to

I Built RepoFleet to Manage One Feature Across Multiple Git Repositories

When one feature touches multiple repositories, the Git workflow can quickly become repetitive. You may need to: Create the same branch in several repositories Pull the latest changes in each project Check the status of every repository Remember which repositories belong to the same task Move between directories repeatedly A typical workflow might look like this: cd api git switch -c fix/123-auth cd ../frontend git switch -c fix/123-auth cd ../worker git switch -c fix/123-auth I built RepoFleet to simplify this workflow. What Is RepoFleet? RepoFleet is an issue-centered CLI tool for managing Git workflows across multiple repositories. Instead of managing each repository separately, you create one issue context: rf issue create 123 --name auth --type fix RepoFleet creates and manages the related branches across your repositories. You can then check everything from one place: rf issue status One issue. Multiple repositories. One workflow. The Problem Imagine that one feature requires changes in three repositories: api frontend worker Without RepoFleet, you might need to run: cd api git fetch git switch -c feature/123-auth cd ../frontend git fetch git switch -c feature/123-auth cd ../worker git fetch git switch -c feature/123-auth Later, you need to repeat a similar process to check status, pull changes, or push branches. This works, but it becomes inconvenient when you manage many tasks across multiple repositories. Why I Built It At work, our codebase was split into multiple repositories. After the split, one task could require changes in several projects. I repeatedly had to: Create matching branches Switch between project directories Fetch updates Check Git status in every repository Remember which repositories belonged to each issue I wanted a workflow centered around the issue, rather than individual repository directories. That idea became RepoFleet. _Example Workflow _Create an issue context rf issue create 123 --name authentication --type feature Add repositor

Mehran Zand 2026-07-14 23:24 👁 3 查看原文 →
The Verge AI

X admits its broken algorithm made the site feel like a ‘battleground’

X's head of product, Nikita Bier, admitted in a post on Monday that X's algorithm was "missing" data about surfacing posts from people who you've followed back. Now, he says a tweak will "boost visibility of your posts to your mutuals," hopefully enhancing the sense of community instead of highlighting and spreading random arguments, but […]

Stevie Bonifield 2026-07-14 23:20 👁 8 查看原文 →