Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
AplikacjaALX
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Patryk Czarnik
AplikacjaALX
Commits
f3f7dd95
Commit
f3f7dd95
authored
May 09, 2024
by
patryk
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
apache-commons
parent
72e9f773
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
126 additions
and
0 deletions
+126
-0
pom.xml
pom.xml
+10
-0
PrzykladyString.java
src/main/java/apacz/PrzykladyString.java
+55
-0
PrzykladyString2.java
src/main/java/apacz/PrzykladyString2.java
+61
-0
No files found.
pom.xml
View file @
f3f7dd95
...
...
@@ -12,4 +12,13 @@
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>
org.apache.commons
</groupId>
<artifactId>
commons-lang3
</artifactId>
<version>
3.14.0
</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
src/main/java/apacz/PrzykladyString.java
0 → 100644
View file @
f3f7dd95
package
apacz
;
import
org.apache.commons.lang3.StringUtils
;
public
class
PrzykladyString
{
public
static
void
main
(
String
[]
args
)
{
String
[]
a
=
{
"Ala"
,
"Ola"
,
""
,
"Ewelina"
,
" "
,
null
};
String
[]
b
=
{
"Ala"
,
"Ola"
,
"Ewelina"
};
String
[]
c
=
{
" "
,
""
,
null
};
// Pisząc w "zwykłej Javie" gdy chcemy wypisać z tablicy a wszystkie napisy, które nie są puste
// trzeba uwzględnić możliwość, że wartość jest nullem
int
ile
=
0
;
for
(
String
s
:
a
)
{
if
(
s
!=
null
&&
!
s
.
isBlank
())
{
System
.
out
.
println
(
s
);
ile
++;
}
}
System
.
out
.
println
(
"tyle: "
+
ile
);
System
.
out
.
println
();
// biblioteka Apache Commons Lang oferuje gotowe metody umieszczona w klasach narzędziowych
// np. dla stringów mamy klasę StringUtils.
ile
=
0
;
for
(
String
s
:
a
)
{
if
(
StringUtils
.
isNotBlank
(
s
))
{
System
.
out
.
println
(
s
);
ile
++;
}
}
System
.
out
.
println
(
"tyle: "
+
ile
);
System
.
out
.
println
();
// operacje dla całych tablic (lub wartości podawanych po przecinku)
if
(
StringUtils
.
isNoneBlank
(
a
))
{
System
.
out
.
println
(
"W a są same dobre napisy"
);
}
else
{
System
.
out
.
println
(
"W a są też pustaki"
);
}
if
(
StringUtils
.
isNoneBlank
(
b
))
{
System
.
out
.
println
(
"W b są same dobre napisy"
);
}
else
{
System
.
out
.
println
(
"W b są też pustaki"
);
}
if
(
StringUtils
.
isAllBlank
(
c
))
{
System
.
out
.
println
(
"ccc"
);
}
}
}
src/main/java/apacz/PrzykladyString2.java
0 → 100644
View file @
f3f7dd95
package
apacz
;
import
static
org
.
apache
.
commons
.
lang3
.
StringUtils
.
isAllBlank
;
import
static
org
.
apache
.
commons
.
lang3
.
StringUtils
.
isNoneBlank
;
import
static
org
.
apache
.
commons
.
lang3
.
StringUtils
.
isNotBlank
;
public
class
PrzykladyString2
{
public
static
void
main
(
String
[]
args
)
{
String
[]
a
=
{
"Ala"
,
"Ola"
,
""
,
"Ewelina"
,
" "
,
null
};
String
[]
b
=
{
"Ala"
,
"Ola"
,
"Ewelina"
};
String
[]
c
=
{
" "
,
""
,
null
};
// Pisząc w "zwykłej Javie" gdy chcemy wypisać z tablicy a wszystkie napisy, które nie są puste
// trzeba uwzględnić możliwość, że wartość jest nullem
int
ile
=
0
;
for
(
String
s
:
a
)
{
if
(
s
!=
null
&&
!
s
.
isBlank
())
{
System
.
out
.
println
(
s
);
ile
++;
}
}
System
.
out
.
println
(
"tyle: "
+
ile
);
System
.
out
.
println
();
// biblioteka Apache Commons Lang oferuje gotowe metody umieszczona w klasach narzędziowych
// np. dla stringów mamy klasę StringUtils.
ile
=
0
;
for
(
String
s
:
a
)
{
if
(
isNotBlank
(
s
))
{
System
.
out
.
println
(
s
);
ile
++;
}
}
System
.
out
.
println
(
"tyle: "
+
ile
);
System
.
out
.
println
();
// operacje dla całych tablic (lub wartości podawanych po przecinku)
if
(
isNoneBlank
(
a
))
{
System
.
out
.
println
(
"W a są same dobre napisy"
);
}
else
{
System
.
out
.
println
(
"W a są też pustaki"
);
}
if
(
isNoneBlank
(
b
))
{
System
.
out
.
println
(
"W b są same dobre napisy"
);
}
else
{
System
.
out
.
println
(
"W b są też pustaki"
);
}
if
(
isAllBlank
(
c
))
{
System
.
out
.
println
(
"ccc"
);
}
if
(
isNoneBlank
(
"Ala"
,
"Ola"
,
"Ela"
))
{
System
.
out
.
println
(
"nie musi być tablica"
);
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment